Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database 如何在MongoDB中查询数组?_Database_Mongodb_Mongoose_Nosql - Fatal编程技术网

Database 如何在MongoDB中查询数组?

Database 如何在MongoDB中查询数组?,database,mongodb,mongoose,nosql,Database,Mongodb,Mongoose,Nosql,我是MongoDB的新手,我有以下文件 { "_id" : ObjectId("604b7d62b19a72a2b89028e6"), "name" : "ram", "tags" : [ "mobile", "iphone", "india" ] } {"_id" : ObjectId("604b7d83b

我是MongoDB的新手,我有以下文件

{ "_id" : ObjectId("604b7d62b19a72a2b89028e6"), "name" : "ram", "tags" : [ "mobile", "iphone", "india" ] }
{"_id" : ObjectId("604b7d83b19a72a2b89028e7"), "name" : "shyam", "tags" : [ "mobile", "iphone", "india" ] }
{ "_id" : ObjectId("604b7d9bb19a72a2b89028e8"), "name" : "ravi", "tags" : [ "mobile", "android", "india" ] }
{ "_id" : ObjectId("604b7db5b19a72a2b89028e9"), "name" : "aman", "tags" : [ "mobile", "android", "india" ] }
{ "_id" : ObjectId("604b7db5b19a72a2b89028e9"), "name" : "aman", "tags" : [ "windows", "usa" ] }
{ "_id" : ObjectId("604b7db5b19a72a2b89028e9"), "name" : "aman", "tags" : [ "tech", "apple", "microsoft" ] }
如何编写查询,以便如果我查询以下标签
[“mobile”、“android”、“12”、“pro”]
,我将得到以下结果

{ "_id" : ObjectId("604b7d9bb19a72a2b89028e8"), "name" : "ravi", "tags" : [ "mobile", "android", "india" ] }
{ "_id" : ObjectId("604b7db5b19a72a2b89028e9"), "name" : "aman", "tags" : [ "mobile", "android", "india" ] } 
{ "_id" : ObjectId("604b7d62b19a72a2b89028e6"), "name" : "ram", "tags" : [ "mobile", "iphone", "india" ] }
{ "_id" : ObjectId("604b7d83b19a72a2b89028e7"), "name" : "shyam", "tags" : [ "mobile", "iphone", "india" ] }
演示-

使用

$in运算符选择字段值等于指定数组中任何值的文档。要在表达式中指定$in,请使用以下原型:


查询结果和示例完全相同,请详细说明以下标签的查询
[“mobile”、“android”、“12”、“pro”]
?您想要与所有或任何文档匹配的文档?在示例文档中添加一些失败案例。好的,我已经添加了一些失败案例。
db.collection.find({
  tags: { $in: [ "mobile", "android", "12", "pro" ] }
})