zoukankan      html  css  js  c++  java
  • Mogoose API 操作记录

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

  • 相关阅读:
    客户端不能连接MySQL
    Linux 7.x 防火墙&端口
    MYSQL.版本查看-LINUX
    Java之.jdk卸载-Linux
    Redis.之.环境搭建(集群)
    Elasticsearch.安装插件(head)
    Linux安装Nodejs
    Linux.ls 查看常用参数
    Elasticsearch.安装(单节点)
    Andrew NG 机器学习编程作业3 Octave
  • 原文地址:https://www.cnblogs.com/zhengchunhao/p/5666714.html
Copyright © 2011-2022 走看看