我有一个集合名称产品,其中包含如下文档:
{
"_id" : ObjectId("5acbc75adcc6772eecfca8a2"),
"name" : "HP 15q-by002ax (2TZ85PA) Notebook (APU Dual Core A9/ 4GB/ 1TB/
WIn10/ 2GB Graph)",
"price" : "24990",
"brand" : "HP",
"tags" : [
"hp",
"15q",
"by002ax",
"2tz85pa",
"notebook",
"apu",
"dual",
"core",
"a9",
"4g"
], "specifications" : {
"full_specs" : {
"General" : {
"Model" : "2TZ85PA#ACJ",
"Utility" : "Everyday Use",
"OS" : "Windows 10 Home (64-bit)",
"Dimensions" : "253.7 x 380 x 23.88 mm",
"Weight" : "2.1 Kg",
"Warranty" : "1 Year Onsite Warranty"
},
"Display" : {
"Type" : "HD LED Backlit Widescreen BrightView Display",
"Touch" : "No",
"Size" : "15.6 inches",
"Resolution" : "1366 x 768 pixels",
"PPI" : "~ 100",
"Aspect Ratio" : "16"
},
"Connectivity" : {
"Ethernet" : "Integrated 10/100/1000 Gigabit LAN",
"WiFi" : "IEEE 802.11b/g/n",
"Bluetooth" : "v4.0",
"Lan Port" : "Yes",
"USB Ports" : "1 x USB 2.0, 2 x USB 3.0",
"HDMI" : "1 x HDMI Port (v1.4b)",
"Card Reader" : "3-in-1 Card Reader (SD, SDHC, SDXC)",
"Microphone In" : "Yes",
"Security Lock Port" : "Kensington Lock Slot"
},
"Input" : {
"Camera" : "HP TrueVision HD Webcam",
"Keyboard" : "Full Size Textured Island-style Keyboard with
Numeric Keypad",
"Pointer Device" : "Multi Gesture Touchpad",
"Inbuilt Microphone" : "Single Digital Microphone",
"Speakers" : "Built-in, Stereo Speakers",
"Optical Drive" : "Yes",
"Optical Drive Speed" : "8x"
},
"Processor" : {
"Processor" : "AMD APU Dual Core A9 A9-9420",
"Speed" : "3 GHz, Dual Core (Turbo Boost Upto 3.52 GHz)",
"Cache" : "1 MB",
"Brand" : "AMD",
"Series" : "APU Dual Core",
"Model" : "A9-9420"
},
"Graphics" : {
"GPU" : "AMD Radeon 520 Graphics",
"Dedicated Memory" : "2 GB DDR3",
"Brand" : "AMD"
},
"Memory" : {
"RAM" : "4 GB DDR4",
"RAM Bus Speed" : "1866 MHz",
"Maximum RAM Supported" : "Upto 16 GB",
"RAM Slots" : "2",
"Hard Disk Capacity" : "1 TB",
"Hard Disk Speed" : "5400 RPM"
},
"Battery" : {
"Battery" : "4 Cell Battery"
},
"Extra" : {
"Sales Package" : "Laptop, Battery, Power Adaptor, User Guide,
Warranty Documents"
}
}
}},
{
"_id" : ObjectId("5acbc75adcc6772eecfca8a3"),
"name" : "Dell 3565 Notebook (7th Gen APU Dual Core A9/ 6GB/ 1TB/ Win10 Home)",
"price" : "28990",
"brand" : "Dell",
"tags" : [
"dell",
"3565",
"notebook",
"7th",
"gen",
"apu",
"dual",
"core",
"a9",
"6gb",
"1tb"
], "specifications" : {
"full_specs" : {
"General" : {
"Series" : "Inspiron",
"Model" : "A561226SIN9",
"Utility" : "Everyday Use",
"OS" : "Windows 10 Home (64-bit)",
"Warranty" : "1 Year Onsite Warranty"
},
"Display" : {
"Type" : "HD LED Backlit Truelife Display",
"Touch" : "No",
"Size" : "15.6 inches",
"Resolution" : "1366 x 768 pixels",
"PPI" : "~ 100",
"Aspect Ratio" : "16"
},
"Connectivity" : {
"Ethernet" : "10/100/1000 Mbps",
"WiFi" : "IEEE 802.11ac",
"Bluetooth" : "v4.1",
"Lan Port" : "Yes",
"USB Ports" : "1 x USB 2.0, 2 x USB 3.0",
"HDMI" : "1 x HDMI Port (v1.4a)",
"Card Reader" : "3-in-1 Card Reader (SD, SDHC, SDXC)",
"Microphone In" : "Yes"
},
"Input" : {
"Camera" : "Integrated HD Webcam",
"Keyboard" : "English Non-Backlit Keyboard",
"Keyboard Backlit" : "Yes",
"Pointer Device" : "Touchpad",
"Inbuilt Microphone" : "Single Digital Microphone",
"Speakers" : ", Stereo Speakers",
"Sound" : "2 x Tuned Speakers with Waves MaxxAudio Pro",
"Optical Drive" : "Yes",
"Optical Drive Speed" : "8x"
},
"Processor" : {
"Processor" : "AMD APU Dual Core A9 7th Gen A9-9400",
"Speed" : "2.4 GHz, Dual Core",
"Cache" : "1 MB",
"Brand" : "AMD",
"Series" : "APU Dual Core",
"Model" : "A9-9400"
},
"Graphics" : {
"GPU" : "Integrated AMD Graphics",
"Brand" : "AMD"
},
"Memory" : {
"RAM" : "6 GB DDR4",
"RAM Bus Speed" : "2400 MHz",
"Maximum RAM Supported" : "Upto 8 GB",
"RAM Slots" : "2",
"Hard Disk Capacity" : "1 TB",
"Hard Disk Speed" : "5400 RPM"
},
"Battery" : {
"Battery" : "4 Cell Battery",
"Battery Backup" : "Upto 5 Hours"
},
"Extra" : {
"Sales Package" : "Laptop, Battery, Power Adaptor, User Guide, Warranty Documents"
}
}
}
}
现在我在这个集合上查询如下:
product.find({$and:[{"specifications.full_specs.Processor.Brand": {$in: cpu}}, {brand:{$in: brand}}]}).exec(function(error, result){
if(error){
console.log("here is an error in filtering");
}
else {
console.log(result);
var l1 = result.length;
console.log("Result after filtering is ");
console.log(result);
console.log(cpu);
console.log(l1);
console.log("I am here with filtering 2");
console.log("API SUCCESSOR");
res.json({STATUS:"SUCCESSOR"});
}
});
这里cpu和brand是数组的名称。
现在我想查询从上面的查询得到的结果。
我可以查询该结果,如:
db.products.find({price:{$gt:"2900",$lt:"500000"}}).pretty().length();
或我想要的任何其他查询结果。
然后在我的应用程序中返回最终结果。