Mogoose API 操作记录

本文介绍了使用Node.js的Mongoose库连接MongoDB数据库的方法,并通过一个具体示例展示了如何查询特定日期范围内的数据记录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 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'就好了,还没有搞清楚是什么原理

转载于:https://www.cnblogs.com/zhengchunhao/p/5666714.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值