How to delete data in MongoDB by create date? [duplicate] - database

This question already has answers here:
Find and remove all documents whose "createdDate" is one month older
(1 answer)
Remove old records in mongodb based on Month
(5 answers)
Remove documents from a MongoDB collection based on "time" of a Date field
(2 answers)
Remove old records in mongodb
(3 answers)
I want to retrieve values inserted on particular date using _id of mongodb
(1 answer)
Closed 4 years ago.
I have a MongoDB with 380k documents in it and I want to delete all documents which are created before specific date.
Can anyone help me with writing query for this task?
Thank you.

The ObjectId of the document is basically contains timestamp. So you can easily construct ObjectId from timestamp and use $lt operator just like this (python code):
from bson.objectid import ObjectId
ts = datetime.datetime(2017, 1, 1)
doc_id = ObjectId.from_datetime(ts)
result = collection.find({"_id": {"$lt": doc_id}})

Related

Custom ID in Firebase [duplicate]

This question already has answers here:
Firestore and Auto Increment Ids
(1 answer)
Firestore managing auto increment ID [closed]
(2 answers)
How to auto increment document id in firestore based on the input number
(2 answers)
Closed 3 months ago.
I am building an application to generate invoices for my business using React and Firebase. I need each invoice to have an ID that represents the year, and the invoice number. For example 20220001, 20220002, 20230001. I'm just not sure how to accomplish this so I was wondering if anyone could help me find a solution.
I haven't tried much, since i'm new to firebase and want to make sure I do it right.

How to fetch data from firestore based on date range in react js. For example: get all documents created between november 5th and november 16th [duplicate]

This question already has answers here:
How to query data between two dates range using Cloud FireStore?
(2 answers)
Firestore query by date range
(13 answers)
Firestore query date range with using 'where'
(1 answer)
Firestore query with timestamp
(1 answer)
Closed 5 months ago.
Unsure how to even approach it. But i am looking for a way to filter documents by a certain date range. The ranges i am looking to query for are: documents created today, this week, this month, and this year.
Any advice is much appreciated

Previous years registered: Excel COUNTIF and RETURN for X years

UPDATED screenshot after attempting #Dude_Scott's suggestion:
Desired output of data is in the blue table.
Our data includes users who have registered between 1989-2016.
All have registered at least once.
Some register every year and some skip years.
Our question is for each year, find how many years previous users registered.
We want results to be 0yr, 1yr, 2yr, 3yr, etc., for each year.
Arrays are working correctly.
I've organized the data structure in Excel this way:
1) UserID All Years
For year 1989, result is 0, since it was the first year of data collection.
For year 1990, this formula returns the expected count:
=COUNT(IF($B$2:$B$11613=1989,1/COUNTIFS($A$2:$A$11613,$A$2:$A$11613,$B$2:$B$11613,1989)))
Beginning with year 1991 is where I am tripped up: I can't find for multiple years.
This formula is not working:
=COUNT(IF(AND(OR($B$2:$B$11613=1989,1990,1/COUNTIFS($A$2:$A$11613,$A$2:$A$11613,$B$2:$B$11613,1989,1990)))))
Where do I argue "COUNTIF 0 yr, 1 yr, 2 yr", etc. Thanks in advance. --f66
Since your using COUNTIF, I'm assuming you can use SUMPRODUCT also. In the below screen shot I am using this formula
=SUMPRODUCT(($A$2:$A$11=$D3)*($B$2:$B$11<=F$2))&" yr"
Without a sample of the workbook its a little difficult to determine what the output of your data should look like, but give it a go.
Side note, I would suggest updating the User ID and Years into a table format and giving it a named range, so you don't iterate though tens of thousands of lines with the array formula.
I may be reading this all wrong, but this seems to be a straightforward use case for a pivot table!
Select your data range
Set USERID as your row headings
Set YEARS as your column headings
Set count of USERID as your values
I do not use excel anymore, but below is a link to output for doing this with test data on google sheets.

Create datetime form dd/mm/yy(yy) [duplicate]

This question already has answers here:
PHP Date Formatting not working wen using date_format()
(2 answers)
Closed 6 years ago.
I try to create datetime form dd/mm/yy(yy), but with no success?
code:
var_dump(date_create("22/12/2016"));
or
var_dump(strtotime("22/12/2016"));
neither works. This is the demo. Why I cannot create from this format?
before date_create convert your date into an acceptable date format
using
DateTime::createFromFormat
(PHP 5 >= 5.3.0, PHP 7)
DateTime::createFromFormat -- date_create_from_format — Parses a time string according to a specified format
var_dump(date_create(DateTime::createFromFormat('d/m/Y', "22/12/2016")->format('Y-m-d')));
Demo

How do I compare only the time part? [duplicate]

This question already has an answer here:
Using DateTime?.Value.TimeOfDay in LINQ Query
(1 answer)
Closed 8 years ago.
I'm storing a time span in Sql Server as two columns of type datetime. (start and end)
So the date part of each column needs to be ignored.
Given some c# datetime instance, using an EF linq query, how can I determine whether the c# datetime's time is within the time span?
So the date part of all three values is ignored.
You can extract TimeOfDay property from DateTime that gives you the TimeSpan representing the time into the day:
DateTime dt = DateTime.Now;
dt.TimeOfDay;
Returns TimeSpan :
14:16:22.3100098

Resources