时间:2021-07-01 10:21:17 帮助过:25人阅读
var mongodb=require(‘mongodb‘); var server=new mongodb.Server(‘127.0.0.1‘,27017,{}); var client=new mongodb.Db(‘mydatabase1‘,server,{w:1});//数据库名?存储位置? client.open(function(err){ if(err){throw err;} client.collection(‘test_insert‘,function(err,collection){//表名? if(err) throw err; console.log(888888); collection.insert( { "title":"i like you", "body":"it‘s true" }, {safe:true}, function(err,documents){//安全模式表明数据库操作在回调之前完成 if(err) throw err; console.log(‘document id is‘+ JSON.stringify(documents)); }); collection.find({"title":"i like you"}).toArray( function(err,results){ if(err) throw err; console.log(results); } ); }); });
01demo-mongodb
标签:ring pre src class div insert tle row javascrip