[SERVER-43702] redact with nested arrays Created: 28/Sep/19 Updated: 01/Oct/19 Resolved: 01/Oct/19 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Paulo Leite | Assignee: | Carl Champain (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Operating System: | ALL | ||||
| Participants: | |||||
| Description |
|
want to prune the elements of a nested array which do not satisfy a certain condition: The structure of my document is: {"array1":[{"array2":[{"field1":{"field2":"MATCH"}}]}]}The redact query I´m trying to do is: db.getCollection("collection").aggregate([{"$match" : {"array1.array2.field1.field2" : "MATCH",{"$redact" : {"$cond" : {"if" : {"$in" : ["$array1.array2.field1.field2",["MATCH"]]},"then" : "$$KEEP","else" : "$$PRUNE"}}}]);}} I never can get any result. However if I replace "$array1.array2.field1.field2" with "MATCH" I get a true condition and keeps all the documents. My question is what am I doing wrong for the value of the expression "$array1.array2.field1.field2" never to be equal to "MATCH" if it is the value of field2? I also need the returned documents in its original structure.
I'm using MongoDB 4.0
|
| Comments |
| Comment by Carl Champain (Inactive) [ 01/Oct/19 ] |
|
Hi paulo.nuno.leite@gmail.com, The SERVER project is for bugs and feature suggestions for the MongoDB server. As this ticket does not appear to be a bug, I will now close it. If you need further assistance troubleshooting, I encourage you to ask our community by posting on the mongodb-user group or on Stack Overflow with the mongodb tag. Kind regards,
|