0

Lets say I have a 10 documents of Item in the database.

Lets retrieve 3 documents of Item matching some condition using limit().

documents = Item.objects(somefield=somecondition).limit(3)

Now if I do

documents.update(), mongoengine updates all the documents in the database matched by the query not just the 3 documents I have limited my query to.

I also tried setting multi=False in the params, but then only one document gets updated.

Is there anyway to do update while querying itself instead of looping over the documents one by one?

Sri Hari Vignesh
  • 256
  • 4
  • 11

1 Answers1

0

As far as I know there is no available solution to your problem provided by MongoDB. However you could try something like this

documents.forEach(
    function (e) {
        e.field = 'value';
        db.collection.save(e);
    }
);
mic4ael
  • 7,974
  • 3
  • 29
  • 42