[SERVER-11645] Allow multi update without $ operator Created: 08/Nov/13  Updated: 06/Dec/22  Resolved: 29/Jun/19

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.5.2
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Andre Spiegel Assignee: Backlog - Query Team (Inactive)
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to DOCS-2213 Explain behavior of multi update with... Closed
Assigned Teams:
Query
Participants:

 Description   

An update with multi: true is currently only allowed if it uses $ operators, such as $set to modify individual fields. If you try to replace the entire document, you get the error message "multi update only works with $ operators".

After some discussion, it was concluded that there are indeed cases where it makes sense to replace a number of documents with a given, single document (except the _id field, obviously).

So this ticket requests to remove the above error condition and carry out the operation as usual, i.e. replace all the selected documents with the update document.



 Comments   
Comment by Asya Kamsky [ 29/Jun/19 ]

4.2 added aggregation pipeline syntax for updates and this restriction is not carried to those updates, so you can achieve this with update clause: [ {$replaceWith: {new-object} } ] and it works.

Comment by Eliot Horowitz (Inactive) [ 08/Nov/13 ]

My point is yes.

Comment by Andre Spiegel [ 08/Nov/13 ]

But is that enough to warrant a special case and forbid the operation altogether? There are in fact useful scenarios for it and I don't see how it does any harm. Also, glancing over the code, it doesn't seem like it would require any special implementation effort – it's already there.

Comment by Eliot Horowitz (Inactive) [ 08/Nov/13 ]

Yes, which makes sense in the singular case, not so much in the plural.

Comment by Andre Spiegel [ 08/Nov/13 ]

Although that's exactly what it already does right now when multi is false, isn't it?

Comment by Eliot Horowitz (Inactive) [ 08/Nov/13 ]

This seems like a pretty sketchy idea...
"replace" should be all fields, which cannot work in this case.
You would be implicitly pulling the _id from the old and merging with the stuff on the right.
Which will quickly turn into "i want these fields"

Generated at Thu Feb 08 03:26:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.