I have a data set returned by find command in MongoDB. How do I search for the value and field of DeviceJson[] in the given data
{ location: [],
_id: 5d42d171e7ceef2a90245470,
farmName: 'Xilo',
description: 'This is test from Postman Api Request',
farmAddDate: 2019-08-01T11:48:01.883Z,
device:
[
{ _id: 5d441878f1877637cc712d07,
deviceName: 'Xki',
deviceType: 'Muc',
description:
'This is test for updation of specific data in a specfic farm .Test Pass',
deviceLocation: [Array],
Parameter: 'Hello Happy',
Topic: 'v1/Xki/11,180/Hello Happy' },
{ _id: 5d4418953968370e64c32e1f,
deviceName: 'Xki',
deviceType: 'Muc',
description:
'This is test for updation of specific data in a specfic farm .Test Pass',
deviceLocation: [Array],
Parameter: 'Hello Happy',
Topic: 'v1/Xki/11,180/Hello Happy' },
{ _id: 5d4425548b3cf92af46e2c9a,
deviceName: 'Xki',
deviceType: 'Muc',
description:
'This is test for updation of specific data in a specfic farm .Test Pass',
deviceLocation: [Array],
Parameter: 'Hello Happy 1',
Topic: 'sagita/5d42d171e7ceef2a90245470/Xki/11,180/Hello Happy 1' },
{ _id: 5d44256d8b3cf92af46e2c9b,
deviceName: ' DeviceX01',
deviceType: ' Test',
description: ' This is a test',
deviceLocation: '11.22,33.12',
Parameter: ' set',
Topic:
'sagita/5d42d171e7ceef2a90245470/ DeviceX01/11.22,33.12/ set',
DeviceJson: [Array] }
]
}
The data Set I have saved in an array called usdData=[] and was looping through its index and this is resultant and I want to search even Interior and the value of DeviceJson in the schema. How can I do so?
var usdData=[];
collection.findOne({"email":Username},function (err,doc) {
if (err) throw err;
usdData=doc.farm;
for (let index = 0; index < usdData.length; index++) {
if (usdData[index].farmName === gotfarmName) {
return usdData[index];
}
const element = usdData[index];
// const dElement = JSON.stringify(element);
// console.log("Array started here \n"+dElement);
// const ddElement= JSON.parse(dElement) ;
console.log(usdData[1]);
}
return console.log();
});