美文网首页
mongodb相关sql查询

mongodb相关sql查询

作者: 吴世浩 | 来源:发表于2017-05-22 23:18 被阅读70次

    一、好言

    心酸纵有千百种,沉默不语最难过。

    二、背景

    产品要我查询数据,结果一看数据存在mongodb里面,咔嚓,mongodb的语法我还真没写过,所以就边搜边查询了,顺便记录下。

    三、语句

    3.1、查询时间段:

    db.UserRecord.find({createTime:{'$gte':new Date('2017/05/21
    08:00:00'),'$lte':new Date('2017/05/22
    08:00:00')},id:123}).sort({createTime:1}).count()
    

    说下查询时间的问题,转换时间时候需要向加八小时,所以上面是查询5月21号的数据,并且按照时间排序,1是升序,-1是降序
    db.集合.find({column:param})的形式。

    3.2 、查询id=123的数据

    db.getCollection('UserRecord').find({id:123});
    

    3.3 、查询id=123的数据的总数

    db.getCollection('DialogDeviceUserRecord').find({id:123}).count();
    
    var arr = db.getCollection('UserRecord').find({});
    while(arr.hasNext()) db.UserRecord.insert(arr.next());
    mongoexport -uroot -pxxxxxx --authenticationDatabase=admin -d device -c UserRecord --type=csv -f device -o /tmp/1.txt
    
    db.UserRecord.ensureIndex({'userid':1, 'no':1}, {background:true})
    

    查询索引:

    db.getCollection('test').getIndexes()
    

    相关文章

      网友评论

          本文标题:mongodb相关sql查询

          本文链接:https://www.haomeiwen.com/subject/isyixxtx.html