[SERVER-65323] when we are trying to use $ifnull inside $cond we r getting exat oposite result Created: 07/Apr/22 Updated: 27/Oct/23 Resolved: 12/Apr/22 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Critical - P2 |
| Reporter: | jibanjyoti dhal | Assignee: | Chris Kelly |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Participants: |
| Description |
| Comments |
| Comment by Chris Kelly [ 12/Apr/22 ] | |
|
I went ahead and tested the query with your sample data, and $ifNull appears to be behaving as expected on this query. Specifically, it is following the behavior as described in MongoDB's documentation for $ifNull. $ifNull is checking to see if the value is null, which it is doing successfully, and is setting the value of the startTime field in your projection to either true or false, depending on whether it is null. However, your projection displays both the true and false cases in the final result. You can filter this further by adding another $match pipeline stage which limits your results further based on which are true or false in this case. I.e.
In the interest of performance, it is worth placing $match filters like this as early in your aggregation pipeline as possible. However, adding another $match at the end of your pipeline appears to resolve your immediate issue. For future questions like this, I recommend asking the community for help by posting on the MongoDB Developer Community Forums. If the discussion there leads you to suspect a bug in the MongoDB server, then we'd want to investigate it as a possible bug here in the SERVER project. Regards,
| |
| Comment by Tim Fogarty [ 07/Apr/22 ] | |
|
Hi, this Jira project is only for tracking development and bugfixes for the MongoDB Database Tools (mongoimport, mongodump, etc.). So this isn't the best place to get an answer to your question. Since this has to do with MongoDB server behavior, I will move this ticket to the Server project. I would recommend also you post your question in the MongoDB Community Forum here: https://community.mongodb.com/. |