2016-08-05 42 views
0

在这里,在下面的代码我试图登录一个获取文档,但整个文件内容查询个人场logged..what可能是可行的解决方案..使用MongoDB的

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' } 
    ] 
+0

使用项目获取单个字段输出。由于您通过'borough'字段查询,它会返回与查询匹配的记录。如果只想获取特定字段,那么项目 – jerry

+0

您只想检索特定字段? – Shrabanee

+0

我想要获取只有自治市镇领域 – Manoj

回答

1

为项目的具体领域,而使用使用以下语法查找查询

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); 
}); 
+0

谢谢你杰瑞!有用 ! – Manoj