mongodb tip-2

1.or 查询的格式:

var condition = {$or:[{field:1},{field:2}]}

2.字符串存储日期也可以用$gt $gte $lt $lte 直接比较

var condition = {

  create_date:{

      $gte:'2017-1-10',

      $lte:'2017-2-2'    

  }

}

3.$not + $eq = $ne   $not + $in = $nin

var condition = {

  field:{

    $not: {
      $eq: 'R'
    } //$ne:'R'

  },

  field1:{

    $nin:[1,2,3]

  }

}

4.正则 regular expression

var condition = {

  field:{

    $regex:/xxx/

  }//field:/xxx/

}

更多参照:http://www.jb51.net/article/48216.htm

原文地址:https://www.cnblogs.com/xuezizhenchengxuyuan/p/6272646.html