I am not sure how to complete this task.
Here is the structure of the document
name: date_created: val:
I need to find unique documents created between January 2011 and October 2011
I know that I can find out the number of documents between two date ranges as
db.collection.find({'date_created': {'$gte': '2011-01-01', '$lt': '2011-10-30'}});
and i can know how
db.runCommand({'distinct': 'collection', 'key': 'name'})
Problem
The problem is that inside the collection there are duplicate documents that need to be deleted.
How can I answer this question?
find out unique documents created between January 2011 and October 2011 where uniqueness is based on 'name' key
UPDATE
@Sergio ansewer is excellent, after executing the request, I got the following result, and you can see that output number < input number , which means that duplicates were deleted
{ "result" : "temp_collection", "timeMillis" : 1509717, "counts" : { "input" : 592364, "emit" : 592364, "output" : 380827 }, "ok" : 1 }
source share