[SERVER-38497] The $exists operator is not working correctly Created: 10/Dec/18 Updated: 10/Dec/18 Resolved: 10/Dec/18 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | 4.0.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Kais Ben Salah | Assignee: | Danny Hatcher (Inactive) |
| Resolution: | Cannot Reproduce | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL | |||
| Steps To Reproduce: | I'm trying to pull nested documents from a field of type array called "workers" that is part of each document of a collection named "production_units", matching the condition that the nested document shouldn't contain 'worker_number' field. In fact I have a nested document which I need to get rid of, and it is structured as:
In order to accomplish that, I used the operator $exists for the match. So this is what I used for performing the update:
However it returned the following result:
Which means that no nested document was matched for $pull. Yet, I tried an alternative command using a hack {$not: {$type: 16} in order to perform something alternative to {$exists: false} for the match, but it worked using the following update syntax:
Resulting in the following output:
And afterwards, I realized that the nested document I wanted to delete, was removed. |
|||
| Participants: |
| Description |
| Comments |
| Comment by Danny Hatcher (Inactive) [ 10/Dec/18 ] | ||||||||||||||||||||||||||||||
|
Hello, Because neither of us are able to reproduce this issue, I will close this ticket. If you are able to encounter this problem in a reliable manner, please let us know on this ticket. In general, it is a good idea to reach out on the mongodb-user group or Stack Overflow with the mongodb tag for discussions like this. Quite often the community has run into the same problems before and know a way to fix it. Thank you, Danny | ||||||||||||||||||||||||||||||
| Comment by Kais Ben Salah [ 10/Dec/18 ] | ||||||||||||||||||||||||||||||
|
Hello Daniel, I re-tried to push the document I described above, and repeated the update command, however it has worked fine. The test case you provided worked for me as well. Honestly I don't know why it didn't work the previous time - I'm unable to determine the cause of the issue. | ||||||||||||||||||||||||||||||
| Comment by Danny Hatcher (Inactive) [ 10/Dec/18 ] | ||||||||||||||||||||||||||||||
|
Hello, On my local version of 4.0.4 I believe I was able to replicate your scenario but everything worked as expected. Can you please let me know the difference between my test and yours?
Thank you, Danny |