Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在查询带有{"foo": "a"},而不是的文档{"foo":["a", "b"]}。
{"foo": "a"}
{"foo":["a", "b"]}
如何在 mongodb 中进行精确查询?
由于问题SERVER-1475导致这两种情况下$type的foo字段都被报告为字符串,这非常困难。
$type
foo
一种解决方法是测试是否存在数组元素以检测数组大小写(并将其从结果中排除):
db.test.find({$and: [{'foo.0': {$exists: false}}, {foo: 'a'}]})