[SERVER-46422] $addField doesn't allow an empty object as a value Created: 26/Feb/20 Updated: 27/Oct/23 Resolved: 03/Mar/20 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 4.2.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Ha Ha | Assignee: | Ian Boros |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | qexec-team | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL | |
| Steps To Reproduce: |
|
|
| Sprint: | Query 2020-03-23 | |
| Participants: | ||
| Case: | (copied to CRM) |
| Description |
It raises Invalid $addFields :: caused by :: an empty object is not a valid value. Found empty object at path attributes with 40180 error code which is weird because simple insert works fine with the same document. Why can't I insert empty field(with {} value) into document? Is there another way to insert a new document to collection with $$NOW(as I know it only usable in update operations) value? |
| Comments |
| Comment by Asya Kamsky [ 16/Jun/20 ] | |
|
I believe $literal (which we document) would be preferable to $const (internal term) | |
| Comment by Ian Boros [ 03/Mar/20 ] | |
|
Filed | |
| Comment by Ian Boros [ 03/Mar/20 ] | |
|
This works as designed. What you probably want to do to avoid this error is to use $const:
My guess for the motivation behind this behavior is that we already use objects to for representing expressions (like {a: {$add: [1, 2]}}). In projections they're also used to represent projections of sub-objects. Having an empty object indicate the special case of "literal empty object" would just make the language a bit harder to reason about.
Let me know if you have other questions about this! | |
| Comment by Carl Champain (Inactive) [ 28/Feb/20 ] | |
|
Thank you for the report. Kind regards, |