mongodb - Match a field property containing $ in the name -


i saved lot of aggregations pipeline collection :

   {         "_id" : objectid("56d06614070b7f2b117b23db"),         "ops" : [             {                 "$unwind" : "$x"             },             {                 "$unwind" : "$y"             },             {                 "$match" : {                     "brand" : "z"                 }             }         ]     } 

i want make statistics on data :

db.apicalls.aggregate([{"$unwind":"$ops"},{"$match":{***...***}}]) 

the result unwind operation alone :

{ "_id" : objectid("56d06631070b7f11117b23d4"), "ops" : { "$match" : { "brand" : "zzz" } } }, { "_id" : objectid("56d06631070b7f11117b23d4"), "ops" : { "$unwind" : "$x" } } 

i want able match $match operations saved collection. haves how select on key "$match" ?

thanks

your question misleading. since $ characters "illegal" property names in mongodb document, "escaped" "slash" \:

{     "_id" : objectid("56d06614070b7f2b117b23db"),     "ops" : [         {             "\$unwind" : "$x"         },         {             "\$unwind" : "$y"         },         {             "\$match" : {                     "brand" : "z"             }         }     ] } 

therefore need include characters in key using $exists operator find \$match:

db.apicalls.aggregate([   { "$unwind": "$ops" },   { "$match": {     "ops.\\$match": { "$exists": true }   }} ]) 

which returns correct document:

{ "_id" : objectid("56d06614070b7f2b117b23db"), "ops" : { "\$match" : { "brand" : "z" } } } 

Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -