[SERVER-2860] findAndModify behaviour unexpected for upsert scenarios Created: 29/Mar/11 Updated: 29/May/12 Resolved: 04/Apr/11 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Question | Priority: | Minor - P4 |
| Reporter: | Remon van Vliet | Assignee: | Mathias Stearn |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
|
This returns an empty document rather than null/nothing : , update : {$set : { a:2}}, fields: {tasks:1}, upsert:true} ) This returns a document with only the _id set rather than the entire newly inserted document : , update : {$set : { a:2}}, fields: {tasks:1}, upsert:true, new: true } ) Is this intended? If so, is it useful to open a JIRA issue to change this? |
| Comments |
| Comment by Remon van Vliet [ 05/Apr/11 ] |
|
Hi Mathias, Okay, sounds reasonable enough. I wasn't sure hence reporting it as a question. And I totally missed that I still had a {fields:..} clause in my example which completely explains the second scenario. Oops |
| Comment by Mathias Stearn [ 04/Apr/11 ] |
|
This is related to http://jira.mongodb.org/browse/SERVER-2757, but the behavior you are seeing is fully expected (at least for now). The reason for the null/{} distinction is that with upsert:false, there is no old OR new object so I consider this an error and return null. If upsert is true then the old object is {}, which isn't possible in any other case unless you filter out _id. The new object with upsert:true should be the full new object. However, you have {fields:{tasks:1}} set which filters out all fields other than _id since there is no tasks field. If you remove the fields option or set {fields: {a:1}} you should see the full object. |