var mongoose=require('mongoose'), Schema=mongoose.Schema; mongoose.connect('mongodb://localhost:27017/myapp',(err)=>{ if(err)throw err; console.log('连接成功!'); }); //users就是表名 var MyModel = mongoose.model('users', new Schema({ name: String })); //插入一条记录 /*MyModel.create({name:'monica'},(err,result)=>{ if(err)throw err; console.log('saved One!'+result) })*/ /*var users=[{name:'欣然'},{name:'纵横'},{name:'思虑'},{name:'南泱'}]; //插入多条记录 MyModel.insertMany(users,(err,result)=>{ if(err)throw err; console.log('saved Many!'+result) })*/ //查询 /*MyModel.findOne({name:'monica'},(err,result)=>{ if(err)throw err; console.log('find by name',result); }); */ //删除 /*MyModel.deleteOne({ name: 'monica' }, (err,result)=>{ if(err)throw err; console.log('deletedOne'+result); });*/ //更新 MyModel.updateOne({ name: '南泱' }, { name: '苏与' }, (err)=> { if(err)throw err; console.log('updateOne!'); });
emm,查看表数据可下载mongodb可视化工具studio 3t查看,mlab在线查看也可以!