我有一个系列名称产品。
像这样的集合文档
{
"_id" : ObjectId("5ac0b89d08e21c226cc2992c"),
"name" : "Lenovo Ideapad Yoga 510 (80S9002QIH) Laptop (AMD Dual Core A9/ 4GB/ 1TB/ Win10 Home)",
"brand" : "Lenovo",
"tags" : [
"lenovo",
"ideapad",
"yoga",
"510",
"80s9002qih",
"laptop",
"amd",
"dual",
"p1301ktgc5jy"
],
"specifications" : {
"full_specs" : {
"General" : {
"Model" : "80S9002QIH",
"Utility" : "Everyday Use",
"Device Type" : "Hybrid",
"OS" : "Windows 10 Home (64-bit)",
"Warranty" : "1 Year Onsite Warranty"
},
"Display" : {
"Type" : "Full HD LED Backlit Display",
"Touch" : "Yes",
"Size" : "14 inches",
"Resolution" : "1920 x 1080 pixels",
"PPI" : "~ 157",
"Aspect Ratio" : "16"
},
"Connectivity" : {
"Ethernet" : "Gigabit Ethernet",
"WiFi" : "IEEE 802.11ac",
"Bluetooth" : "v4.0",
"Lan Port" : "Yes",
"USB Ports" : "1 x USB 2.0, 2 x USB 3.0",
"HDMI" : "1 x HDMI Port",
"Card Reader" : "4-in-1 Card Reader (SD, SDHC, SDXC, MMC)",
"Microphone In" : "Yes"
},
"Input" : {
"Camera" : "HD Webcam",
"Keyboard" : "Standard Keyboard",
"Pointer Device" : "Touchpad",
"Inbuilt Microphone" : "Built-in Microphone",
"Speakers" : ", Stereo Speakers",
"Optical Drive" : "No"
},
"Processor" : {
"Processor" : "AMD APU Dual Core A9 6th Gen A9-9410",
"Speed" : "2.9 GHz, Dual Core (Turbo Boost Upto 3.42 GHz)",
"Cache" : "2 MB",
"Brand" : "AMD",
"Series" : "APU Dual Core",
"Model" : "A9-9410"
},
"Graphics" : {
"GPU" : "Integrated AMD Graphics",
"Brand" : "AMD"
},
"Memory" : {
"RAM" : "4 GB DDR4",
"Hard Disk Capacity" : "1 TB",
"Hard Disk Speed" : "5400 RPM"
},
"Extra" : {
"Sales Package" : "2 in 1 Laptop, Battery, Power Adaptor, User Guide, Warranty Documents"
}
}
}
}
我有像
这样的数组`var brand_arr = [ 'Acer', 'Asus', 'Dell', 'lenovo' ];
var cpuSpeed = [ '1.5', '2.0', '2.5', '3.0' ];`
我想对我的集合应用过滤,检索我的集合中包含 Brand_arr 数组中数据的任何值的所有文档,然后与 cpuSpeed 数组的任何值进行匹配。
brand_arr 的数据包含文档的品牌键值,cpuSpeed 数组中的数据包含处理器下的速度值。
最佳答案
使用$in
:
product.find({brand: {$in: brand_arr}})
关于node.js - 如何根据数组中的数据过滤我的集合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49600975/