这是一个示例查询:
db.readings.find( {"_id.s" : ISODate("2012-11-01T00:05:00Z") } ).count()
查询在 mongo shell 中工作。但是,在 bash 脚本中或直接在 Ubuntu shell 中
mongo fivemin --eval "printjson(db.readings.find( {"_id.s" : ISODate("2012-11-01T00:05:00Z") } ).count())"
返回一个SyntaxError: missing : after property id (shell eval):1
我似乎找不到查询的问题。我恢复到{ "_id" : {"s" : ...} }
,它仍然给出同样的问题。find().count()
然而有效。
在 bash shell 中也有同样的问题。
由于双引号,这将失败:
mongo fivemin --eval "printjson(db.readings.find( {"_id.s" : ISODate("2012-11-01T00:05:00Z") } ).count())"
但是在单引号中使用 eval 字符串是有效的:
mongo fivemin --eval 'printjson(db.readings.find( {"_id.s" : ISODate("2012-11-01T00:05:00Z") } ).count())'
如果你使用像 $regex 这样的 $ 符号,你需要转义它:
mongo fivemin --eval 'printjson(db.readings.find( {"_id.s" : {"\$regex":"2012-11-01T*"} } ).count())'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)