标签:
1 /** 2 * Created by Administrator on 2016/7/13. 3 */ 4 /** 5 * Created by Administrator on 2016/7/13. 6 */ 7 var mongoose = require(‘mongoose‘); 8 mongoose.connect(‘mongodb://hive2:hive2@172.27.8.112:27017/hive_mongodb‘); 9 10 var db = mongoose.connection; 11 db.on(‘error‘, console.error.bind(console, ‘connection error:‘)); 12 db.once(‘open‘, function (callback) { 13 console.log(‘open!‘); 14 15 var clientsSchema = mongoose.Schema({ 16 acsn: String, 17 onlineDay: String, 18 clientMacCounts: String 19 }); 20 21 var clientsModel = mongoose.model(‘historyclients_day‘, clientsSchema); 22 23 clientsModel.find().where(‘onlineDay‘).gt(‘2015-06-30‘).lt(‘2015-08-01‘).exec(function(err, clients){ 24 if (err){ 25 console.log(err); 26 } 27 else { 28 var list = []; 29 30 for(var i=0;i<clients.length;i++){ 31 console.log(clients[i].clientMacCounts); 32 } 33 } 34 }); 44 });
官方参考手册:
http://www.nodeclass.com/api/mongoose.html
http://mongoosejs.com/docs/index.html
ps: 刚开始find不到数据,后来把集合名手动加了个 s,变成‘historyclients_days‘就好了,还没有搞清楚是什么原理
标签:
原文地址:http://www.cnblogs.com/zhengchunhao/p/5666714.html