有没有办法搜索所有字段和值(除了_id)包含在给定文档字段中的文档?
示例:
{_id:..., "field1" : 2 , "field2" : 3}
{_id:..., "field1" : 2 , "field2" : 4}
{_id:..., "field1" : 2 , "field3" : 1}
要放入查询的文档:
{"field1" : 2 , "field2" : 4, "field3" : 1}
预期结果:
{_id:..., "field1" : 2 , "field2" : 4}
{_id:..., "field1" : 2 , "field3" : 1}
答案 0 :(得分:1)
下面应该有效。你可以使用https://docs.mongodb.org/manual/reference/operator/query/or/
db.collection_name.find({"$or":[{"field1" : 2},{"field2" : 4},{"field3" : 1}]})