[SERVER-1581] change update() to be consistent with find() Created: 06/Aug/10  Updated: 06/Dec/22  Resolved: 11/Aug/17

Status: Closed
Project: Core Server
Component/s: Usability
Affects Version/s: 1.6.0
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Nick Leippe Assignee: Backlog - Query Team (Inactive)
Resolution: Won't Fix Votes: 3
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

all


Issue Links:
Related
is related to SERVER-1690 justOne flag for updates Closed
Assigned Teams:
Query
Backwards Compatibility: Major Change
Participants:

 Description   

How about changing update() to be consistent with find().

Make update() by default affect all records matched, unless a limit() is supplied
This allows the removal of update's currently optional "multi" argument.

Furthermore, an updateOne() helper could be added, similar to findOne(). (Though not necessary, API symmetry can be nice.)

Many new people get tripped up by missing the multi flag on update()--it's not the expected behavior. A self-consistent API is a usability win.

Any code that specifies a unique _id for the criteria will not be affected. Most code that doesn't probably wants to affect all matching records anyways.



 Comments   
Comment by Dwight Merriman [ 05/Sep/11 ]

this makes sense to me but non-backward breaking is the tricky part. thus it may be better to just do it in the drivers - they really control their default for updates anyway. could have a new update method in a driver with the new default for example.

Comment by Nick Leippe [ 06/Aug/10 ]

I think just about anyone coming from SQL will expect it. (I'll hazard a guess that a lot of people come with SQL knowledge.) As will many people that are learning and started with the find() command before trying update(). I count in both groups.

Comment by Scott Hernandez (Inactive) [ 06/Aug/10 ]

This is a valid request; I'm not sure it is worth the backwards breaking change though.

In Morphia (java type-safe mapper) we have an update and updateFirst method to expose the difference. As you can guess, thedefault update enables the multi-flag. Unfortunately this creates different expectations and understandings from the shell and other drivers, which could be confusing to users.

Unfortunately, not everyone is going to expect the default to be "multi" on update.

Comment by Eliot Horowitz (Inactive) [ 06/Aug/10 ]

I would say this is a highly unlikely change.
Will see if a lot of people agree though

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