让数据库中的记录

{"_id":"1","unit":"a1", "vehicle1" : "car"}
{"_id":"2","unit":"a2", "vehicle1" : "truck", "vehicle2" : "bike"}
{"_id":"3","unit":"b1", "vehicle1" : "car"}
{"_id":"4","unit":"zz", "vehicle1" : "truck", "vehicle2" : "car", "vehicle3" : "car" }

是否有一个命令将查找具有以下参数的条目或所有条目:
db.accidents.find( { vehicle*: "bike" } );

最佳答案

而是有一个车辆阵列。
下面是一个示例json,您可以插入

{"_id":"2", "unit":"a2", "vehicle": ["truck", "bike"]}

您可以查询的方式是:
db.accidents.find({"vehicle":"bike"});

关于mongodb - Mongodb查询从多个键中选择记录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13554391/

10-16 21:25