Spring boot mongo repository support saveAll,but it cause unique index insert error ,so I want use update.
In my case,I want to insert or update 10 documents together.
how to use updateAll?
Spring boot mongo repository support saveAll,but it cause unique index insert error ,so I want use update.
In my case,I want to insert or update 10 documents together.
how to use updateAll?
Though I'm not crystal clear on your question, it sounds like you need to append { multi: true }
to your update query. Please see Update Multiple Documents.
Setting the multi
option updates all documents found by match
.
To update multiple documents, set the multi option to true. For example, the following operation updates all documents where stock is less than or equal to 10:
db.books.update(
{ stock: { $lte: 10 } },
{ $set: { reorder: true } },
{ multi: true }
)
you can use updateMany:
db.collections.updateMany({ query }, {"$set":{ update }}