Reputation: 646
I am creating an automated process to convert Json data into csv file. I am getting Json from Mongo Db. The process start once at 24 Hrs. In this process the json is converted into csv file and that csv file is stored with the current date as a name. Like 2018-03-21.csv. The collection inside db is updating continuously. So, if a process is started on the next day then whole collection element will be converted that takes lots of time.
And yes my task is to create a csv on the daily basis data.
So my question is is there any way or query to select only newly added data ?
Upvotes: 0
Views: 155
Reputation: 1580
Even you don't have "created_at" (or similar) field at your collection, you probably have ObjectId() at your _id field... First four bytes of that ObjectId is timestamp (unix; seconds from epoc) of document creation. So, you make query like db.collection.find({"_id":{$gt:ObjectId(<timestamp_as_hex>+"00000000")}})
Upvotes: 1