我有以下一组测试文档,它们是我插入到mongodb中的,当我使用$where查询数据库时,会得到下面的异常
错误:数据库错误:$where查询,但没有脚本引擎
知道为什么$where子句不起作用吗?
测试数据:
db.things.save({ "_id" : 1, "domainName" : "test11.com", "hosting" : "hostgator.com" })
db.things.save({ "_id" : 2, "domainName" : "test2.com", "hosting" : "aws.amazon.com"})
db.things.save({ "_id" : 3, "domainName" : "test3.com", "hosting" : "aws.amazon.com" })
db.things.save({ "_id" : 4, "domainName" : "test4.com", "hosting" : "hostgator.com" })
db.things.save({ "_id" : 5, "domainName" : "test5.com", "hosting" : "aws.amazon.com" })
db.things.save({ "_id" : 6, "domainName" : "test6.com", "hosting" : "cloud.google.com" })
db.things.save({ "_id" : 7, "domainName" : "test7.com", "hosting" : "aws.amazon.com" })
db.things.save({ "_id" : 8, "domainName" : "test8.com", "hosting" : "hostgator.com" })
db.things.save({ "_id" : 9, "domainName" : "test9.com", "hosting" : "cloud.google.com" })
db.things.save({ "_id" : 10, "domainName" : "test10.com", "hosting" : "godaddy.com" })使用的查询:
db.things.find( { $where:"this.domainName == 'test11.com'“} );
发布于 2014-06-03 17:21:15
除非确实需要,否则请不要使用运算符。然后请不要使用运算符。
有一个更好的方法:
db.things.find({ "domainName": "test11.com" })这是标准的查询表单。你几乎不应该使用,如果你认为你使用了,那么请在这里发布你的问题,这样我们就可以纠正你。
即:
这里的总体观点是,您的查询形式不是必需的,因为它是MongoDB已经以本机方式完成的。
此外,由于您似乎指的是“在线测试外壳”,因此,如果在处理客户端传输的应用编程接口中没有实现禁用JavaScript执行的选项,则会调用对mongod进程可用的选项。
最后一点对于避免可能的黑客利用攻击是有意义的,但MongoDB通常(在最新版本中)非常安全,不会受到脚本注入,因为通过允许在开放环境可用的参数中指定JavaScript,“可能”是可能的。
发布于 2014-06-03 19:23:12
错误可能会出现,因为在mongodb服务器上,可能已经禁用了JavaScript的服务器端执行,可以使用sh.status()来检查这一点。
除非绝对必要,否则不应该使用"$where“查询:它们比常规查询慢得多。
还要检查这些链接如何将"where“子句用于NoSQL注入。
https://stackoverflow.com/questions/24011372
复制相似问题