我正在使用 Clojure 和 congomongo 与 mongodb 交互。
我在集合测试中有一个文档具有以下结构 -
{:_id #<ObjectId 50e8a4de2b5e29d6f4ab3d66>, :fields {:project {:key "test"}}}
并且想根据嵌入的文档字段进行查询:key
当我运行以下命令时 -
(fetch :test {:fields {:project {:key "test"}}})
我得到了错误-
“IllegalArgumentException 没有为键提供值:{:fields {:project {:key "test"}}} clojure.lang.PersistentHashMap.createWithCheck (PersistentHashMap.java:89)”
如果我从 mongodb 控制台运行以下命令,则会返回正确的文档 -
db.test.find({"fields" : {"project" : {"key" : "test"}}})
谢谢你的建议
最佳答案
看起来你只是缺少 :where 关键字
(fetch :test :where {:fields {:project {:key "test"}}})
关于mongodb - 如何使用 congomongo 的 fetch 查询嵌套文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14177256/