-1
如何使用nodejs SDK從mongodb獲取所有文檔?我嘗試了以下方法獲取所有文檔,但無法獲取任何內容,但插入工作正常。如何從mongodb獲取所有文檔?
// Connection URL
var url = config.mongodbConnectionString;
var db: any;
// Use connect method to connect to the Server
MongoClient.connect(url, function (err: any, database: any) {
assert.equal(null, err);
console.log("Connected correctly to server");
db = database;
});
export class MongodbProvider implements IDbProvider {
public getMenus(): any {
var menus: any = [];
try {
db.open(function (err, db) {
var cursor = db.collection('menus').find(function (err, cursor) {
cursor.each(function (err, doc) {
console.log(doc);
menus.push(doc);
});
});
});
}
catch (err) {
console.log(err);
}
return menus;
}
}
你能幫我嗎?
的[?我如何返回從一個異步調用的響應(可能的複製http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-從-AN-異步呼叫) –