二、实例(node.js读取mongodb) 参考node-mongodb-native的文档:https://github.com/mongodb/node-mongodb-native 复制代码 代码如下: 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); } }); }); });