Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb 键为数字时查询子文档?_Mongodb_Mongodb Query - Fatal编程技术网

Mongodb 键为数字时查询子文档?

Mongodb 键为数字时查询子文档?,mongodb,mongodb-query,Mongodb,Mongodb Query,我正在努力编写一个mongodb查询,该查询进入到一个子文档中,以获取一个数字键 我的文件就像 /* The collection m-plan contains the MfgPlan records */ rs0:SECONDARY> db['plan'].find( { $and: [ {displayId: 'MP-1'}, { version: 5 } ] } ).pretty(); { "_id" : ObjectId("5cda661b9

我正在努力编写一个mongodb查询,该查询进入到一个子文档中,以获取一个数字键

我的文件就像

/* The collection m-plan contains the MfgPlan records */
rs0:SECONDARY> db['plan'].find( { $and: [ {displayId: 'MP-1'}, { version: 5 } ] } ).pretty();
{
    "_id" : ObjectId("5cda661b93dbc10001903d52"),
    "activities" : {
        "5cda66c293dbc10001903d57" : [
            "5b198d8c794c820001ee3c25",
            "5b198da4794c820001ee3c2e"
        ],
        "5c86f61f42c68d000165559d" : [
            "5cda66c293dbc10001903d57"
        ],
        "5b198d8c794c820001ee3c25" : [ ],
        "5b198da4794c820001ee3c2e" : [ ]
    },
    "createdByUser" : "rkuhar",
    "createdDate" : ISODate("2021-03-14T06:54:19.154Z"),
    "displayId" : "MP-1",
    "displayName" : "Obliterator 9000"
    "revisionId" : ObjectId("5cda66c293dbc10001903d59"),
    "version" : 5
}
但是我的定位尝试,如“5c86f61f42c68d000165559d”被shell拒绝

rs0:SECONDARY> db['plan'].find( { activities.5c86f61f42c68d000165559d: { $exists: true } } ).pretty();
uncaught exception: SyntaxError: identifier starts immediately after numeric literal :
@(shell):1:33
rs0:SECONDARY> db['plan'].find( { activities."5c86f61f42c68d000165559d": { $exists: true } } ).pretty();
uncaught exception: SyntaxError: missing : after property id :
@(shell):1:33

如果某个键是数字的,如何查询该键是否存在?

如果使用点表示法,则需要将该属性括在引号中。像这样:

db['plan'].find({“activities.5c86f61f42c68d000165559d:{$exists:true}).pretty();
只需尝试
{“activities.5c86f61f42c68d000165559d:{$exists:true}}