我沮丧了两天,因为我是 nodeJS 和 JSon 的新手。由于我的英语不好,我有一个在子数据中搜索数据并将结果放入浏览器的案例。这是我的代码:
var doc = [{
"name": "yadi",
"hobby": [{
"home": "watch news",
"bed_room": "read comics"
}, {
"home": "watch ufc",
"bed_room": "eat candy"
}]
},
"name": "dony",
"hobby": [{
"home": "sleep",
"bed_room": "eat dog food"
}, {
"home": "watch disney",
"bed_room": "breathing"
}]
}];
var db = new Nedb();db.insert(doc, function(err, newDoc) {
console.log(JSON.stringify(newDoc, null, ' '));
//search data
db.find({
"name": "yadi"
}, {
"hobby": {
$elemMatch: {
"home": "watch news"
}
}
}, function(err, docs) {
console.log ("RESULT "+JSON.stringify(docs, null, ' '));
})
})
我怎样才能得到这个结果的数据?
"hobby": [{
"home": "watch news",
"bed_room": "read comics"
}]