码迷,mamicode.com
首页 > 数据库 > 详细

8.nodejs权威指南--MongoDB

时间:2015-11-01 16:34:57      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:

1. MongoDB

var mongo = require(‘mongodb‘);

var host = ‘127.0.0.1‘;

var port = mongo.Connecton.DEFAULT_PORT;

var server = new mongo.Server(host,port,{auto_reconnect:true});

var db = new mongo.Db(‘node-mongo-examples‘,server,{safe:true});

db.open(function(err,db){

      db.collection(‘users‘,function(err,collection){

             collection.insert({name:‘chuck‘},function(err,docs){

                   

             });

             collection.find({name:‘book‘}).toArray(function(err,docs){

                   

             });

             collection.findOne({name:‘book‘},function(err,docs){

                   

             });

             collection.update({name:‘chuck‘},{$set:{name:‘w‘}});

             collection.remove({name:‘chuck‘});

      });

});

db.on(‘close‘,function(err,db){

      console.log(‘close‘);

});

8.nodejs权威指南--MongoDB

标签:

原文地址:http://www.cnblogs.com/SLchuck/p/4927876.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!