Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.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
Database 包含特殊字符的Mongo子字段点表示法_Database_Mongodb - Fatal编程技术网

Database 包含特殊字符的Mongo子字段点表示法

Database 包含特殊字符的Mongo子字段点表示法,database,mongodb,Database,Mongodb,如果我有以下对象: { someMapping: { "some key with spaces & special characters": true, "simple_key": true } } 如何使用点符号查询查找此文档?换言之,如果没有点符号,我怎么能使用$exists来查找它呢 我试过: > db.mycol.findOne({ someMapping: { "some key with spaces & special char

如果我有以下对象:

{
  someMapping: {
     "some key with spaces & special characters": true,
     "simple_key": true
  }
}
如何使用点符号查询查找此文档?换言之,如果没有点符号,我怎么能使用$exists来查找它呢

我试过:

> db.mycol.findOne({ someMapping: { "some key with spaces & special characters": { $exists: true } } })
null
> db.mycol.findOne({ someMapping: { simple_key: { $exists: true } } })
null
> db.mycol.findOne({ "someMapping['some key with spaces & special characters']": { $exists: true } })
null
> db.mycol.findOne({ "someMapping.simple_key": { $exists: true } })
true
以下几点应该行得通

db.mycol.findOne({ "someMapping.some key with spaces & special characters": 
    { $exists: true } })
更多信息请访问

编辑: Mongodb和美元登录字段名


注意:$exists如果字段存在,则返回true。如果要将字段值与true进行比较,只需运行

如果该键包含什么?mongodb不支持点。答案随链接更新
db.mycol.findOne({ "someMapping.some key with spaces & special characters": true })