zoukankan      html  css  js  c++  java
  • mongo常用命令

    MongoDB的模糊查询是通过正则表达式的方式实现的。格式为:

    查询评论内容包含“流量”的所有文档,代码如下:

    /模糊查询字符串/
    db.comment.find({content:/流量/})

    db.comment.find({content:/^加班/})


    db.集合名称.find({ "field" : { $gt: value }}) // 大
    于: field > value
    db.集合名称.find({ "field" : { $lt: value }}) // 小
    于: field < value
    db.集合名称.find({ "field" : { $gte: value }}) // 大于等
    于: field >= value
    db.集合名称.find({ "field" : { $lte: value }}) // 小于等
    于: field <= value
    db.集合名称.find({ "field" : { $ne: value }}) // 不等
    于: field != value

    db.comment.find({thumbup:{$gt:1000}})

    包含使用$in操作符
    查询评论集合中userid字段包含1013和1014的文档:

    db.comment.find({userid:{$in:["1013","1014"]}})

    不包含使用$nin操作符
    查询评论集合中userid字段不包含1013和1014的文档:

    db.comment.find({userid:{$nin:["1013","1014"]}})


    查询评论集合中thumbup大于等于1000 并且小于2000的文档:

    db.comment.find({$and:[ {thumbup:{$gte:1000}} ,{thumbup:
    {$lt:2000} }]})

    查询评论集合中userid为1013,或者点赞数小于2000的文档记录:

    db.comment.find({$or:[ {userid:"1013"} ,{thumbup:{$lt:2000} }]})

    对某列值在原有值的基础上进行增加或减少,可以使用$inc运算符:

    db.comment.update({_id:"2"},{$inc:{thumbup:1}})

  • 相关阅读:
    netbeans中给jpanl添加背景图片制定代码的理解——匿名内部类继承父类
    关于 ASP.NET MVC 中的视图生成
    Python的descriptor (2)
    分享php中四种webservice实现的简单架构方法及实例
    Python 中的 is 和 id
    Python的OO思想
    Python异常记录
    Python单例模式研究
    Python基础笔记
    python 映射列表 学习
  • 原文地址:https://www.cnblogs.com/angdh/p/15526983.html
Copyright © 2011-2022 走看看