[SERVER-23961] $push operation fails on field set to null Created: 28/Apr/16 Updated: 05/May/16 Resolved: 05/May/16 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | 3.2.5 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | nikos efthias [X] | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL | ||||
| Steps To Reproduce: |
i run the command above in order to create an array field and the first element inside will be test but i get the error The field 'accounts' must be an array but is of type NULL in document i am really confused if i have to create a schema beforehand whats the point of using mongodb over some sql database |
||||
| Participants: |
| Description |
|
$push operator wont work Original Summarycannot run push if theres no array field |
| Comments |
| Comment by Kelsey Schubert [ 05/May/16 ] | |||||||||||||||||
|
Hi nikosEfthias, Thank you for the clarification. The field has been set to a value that is not an array, and consequently any push operations on the field will fail. This is intended behavior and is documented here. I would recommend modifying your application to refrain from setting this field to null. Depending on your use case, inserting an empty array or leaving field absent if no accounts exist in your application may better serve your needs. Kind regards, | |||||||||||||||||
| Comment by nikos efthias [X] [ 28/Apr/16 ] | |||||||||||||||||
|
ah now its more clear this is session db on ram and accounts doesnt exist on some accounts so it returns null but still can't mongo handle this kinda stuff why it wont update the null field automatically | |||||||||||||||||
| Comment by Kelsey Schubert [ 28/Apr/16 ] | |||||||||||||||||
|
Hi nikosEfthias, Would you please share the document you are updating? I have run a couple of tests on MongoDB 3.2.5, please see my examples below. If there is no array field the push operation succeeds:
If the field has been explicitly set to null the operation fails:
Does behavior demonstrated in these examples match what you are seeing? Thank you, |