[url=https://github.com/mongodb/node-mongodb-native]https://github.com/mongodb/node-mongodb-native[/url]
var mongodb = require('mongodb');
var server = new mongodb.Server("127.0.0.1",27017,{});//本地27017端口
new mongodb.Db('mongotest',server,{}).open(function(error,client){//数据库:mongotest
if(error) throw error;
var collection = new mongodb.Collection(client,'user');//表:user
collection.find(function(error,cursor){
cursor.each(function(error,doc){
if(doc){
console.log("name:"+doc.name+" age:"+doc.age);
}
});
});
});
运行:
node mongodbTest.js
结果:
name:flyoung age:18
三、写在最后的话
增删改查的demo参考文档