0

I have a document in mongoDB like this :

{
  "_id" : 0,
  "name" : "Sponge Bob",
  "values" : [ [10000, 90], [10001, 92]  . . .],
  "storages" : [{ "number" : 123, "timestamp": "2022-09-08"}, . . .],
  "timestamp" : "2022-09-08"
} 

I want to delete a filtered "storages" objects filtered with a range date, the same thing to "values", but with the number on the first element of the array.

I've trying to do something like :

objects.update({"_id":1}, {"$pull" : {"timestamp" :{"$gt": date}}})

But I do realize that the "$pull" method in this case will not catch all the array of an object, but indeed all the document that will be filtered in that range filter.

So the question is : how do I do this kind of filter to this kind of elements inside the documents with pymongo ?

rickhg12hs
  • 10,638
  • 6
  • 24
  • 42
Chuck.h5
  • 1
  • 3
  • Are your dates really stored as strings, or are they hopefully stored as BSON dates? – rickhg12hs Sep 09 '22 at 15:30
  • They're stored as BSON dates, actually I just find out how to use update method to do a pull on storages values array, the issue is in how to do with the "values" super array – Chuck.h5 Sep 09 '22 at 16:29
  • Perhaps it would be best to edit your question to show actual date format, your solution for `"storages"` and the issue you have with `"values"`. It will help future readers. – rickhg12hs Sep 09 '22 at 17:15
  • Does this answer your question? [Mongoose not updating multiple matches](https://stackoverflow.com/questions/66657369/mongoose-not-updating-multiple-matches) – AlexisG Sep 12 '22 at 08:17

0 Answers0