nodejsæä½mongodbæ¥è¯¢æææ°æ®çæ¹æ³ï¼
var MongoClient = require('mongodb').MongoClient;
var DB_CONN_STR = 'mongodb://localhost:27017/wilsondb1';
var selectData = function(db, callback) {
//è¿æ¥å°è¡¨
var collection = db.collection('tb2');
//æ¥è¯¢æ°æ®
var whereStr = {"name":'wilson001'};
collection.find(whereStr).toArray(function(err, result) {
if(err)
{
console.log('Error:'+ err);
return;
}
callback(result);
});
}
MongoClient.connect(DB_CONN_STR, function(err, db) {
console.log("è¿æ¥æåï¼");
selectData(db, function(result) {
console.log(result);
db.close();
});
});
温馨提示:答案为网友推荐,仅供参考