0

My db is like the followings:

created_on          address       count
2017-4-17T00:00:00  A             2
2017-4-17T01:00:00  A             3
2017-4-15T00:00:00  B             1

I would like to remove the duplicated entry in same day, say, "2017-4-17T00:00:00 A 2", how do I do that?

Language: mongodb shell or Python(pymongo)

  • in what language? – WhatsThePoint Apr 21 '17 at 10:17
  • mongodb shell, or pymongo(python) – Cholidon Kin Apr 21 '17 at 10:19
  • Use the other answer in the marked dupe which uses aggregation framework, for your case you just need to change the group pipeline to `{ "$group": { "_id": { "yearMonthDay": { "$dateToString": { "format": "%Y-%m-%d", "date": "$created_on" } }, "address": "$address" }, "dups": { "$addToSet": "$_id" }, "count": { "$sum": 1 } } }` – chridam Apr 21 '17 at 10:37

0 Answers0