在下面的代码中,我试图记录单个获取的文档,但整个文档内容都是logged..what,这可能是可行的解决方案。
var findDocuments = function(db, callback) {
var collection = db.collection('DATA');
collection.find({'borough':'Bronx'}).toArray(function(err, docs) {
assert.equal(err, null);
console.log("Found the following records");
console.log(docs);
callback(docs);
});
}
output :
[ { _id: 57a47c4a0d0c207a3e0efcc9,
address:
{ building: '1007',
coord: [Object],
street: 'Morris Park Ave',
zipcode: '10462' },
borough: 'Bronx',
cuisine: 'Bakery',
grades: [ [Object], [Object], [Object], [Object], [Object] ],
name: 'Morris Park Bake Shop',
restaurant_id: '30075445' }
]发布于 2016-08-05 20:33:07
要在使用查找查询时投影特定字段,请使用以下语法
collection.find({'borough':'Bronx'}, {borough:1}).toArray(function(err, docs) {
assert.equal(err, null);
console.log("Found the following records");
console.log(docs); // will be array with only borough field and _id
callback(docs);
}); https://stackoverflow.com/questions/38789166
复制相似问题