mongodb exp 操作符号总结

2017-03-30  本文已影响0人  许道龙

exp

qtyGt250: { $ne: [ "$qty", 250 ] }
qtyGt250: { $eq: [ "$qty", 250 ] }
qtyGt250: { $gt: [ "$qty", 250 ] }
 "has bananas" : {
        $in: [ "bananas", "$in_stock" ]
      }
 y: { $ln: "$sales"  }
 qtyLt250: { $lt: [ "$qty", 250 ] }
 result: { $or: [ { $gt: [ "$qty", 250 ] }, { $lt: [ "$qty", 200 ] } ] }
 billing_date: { $add: [ "$date", 3*24*60*6000]}
 result: { $and: [ { $gt: [ "$qty", 250 ] }, { $lt: [ "$qty", 200 ] } ] }
 cmpTo250: { $cmp: [ "$qty", 250 ] }
 { adjustedGrades:
            {
              $map:
                 {
                   input: "$quizzes",
                   as: "grade",
                   in: { $add: [ "$$grade", 2 ] }
                 }
            }
         }
 result: { $not: [ { $gt: [ "$qty", 250 ] } ] }
 {
      $zip: {
        inputs: [
          { $arrayElemAt: [ "$matrix", 0 ] },
          { $arrayElemAt: [ "$matrix", 1 ] },
          { $arrayElemAt: [ "$matrix", 2 ] },
        ]
      }
    }

{ matrix: [[1, 2], [2, 3], [3, 4]] },
{ matrix: [[8, 7], [7, 6], [5, 4]] },

{ "transposed" : [ [ 1, 2, 3 ], [ 2, 3, 4 ] ] }
{ "transposed" : [ [ 8, 7, 5 ], [ 7, 6, 4 ] ] }


{ "_id" : 1, "item" : "abc1", qty: 300 }
{ "_id" : 2, "item" : "abc2", qty: 200 }
{ "_id" : 3, "item" : "xyz1", qty: 250 }

{
    $cond: { if: { $gte: [ "$qty", 250 ] }, then: 30, else: 20 }
}

{ "_id" : 1, "item" : "abc1", "discount" : 30 }
{ "_id" : 2, "item" : "abc2", "discount" : 20 }
{ "_id" : 3, "item" : "xyz1", "discount" : 30 }

 {
           year: { $year: "$date" },
           month: { $month: "$date" },
           day: { $dayOfMonth: "$date" },
           hour: { $hour: "$date" },
           minutes: { $minute: "$date" },
           seconds: { $second: "$date" },
           milliseconds: { $millisecond: "$date" },
           dayOfYear: { $dayOfYear: "$date" },
           dayOfWeek: { $dayOfWeek: "$date" }
}

 numberOfColors: { $size: "$colors" }
 {
       a : { $type: "$a" }
    }
 "Rest stops": { $range: [ 0, "$distance", 25 ] }

{ _id: 0, city: "San Jose", distance: 42 }
{ _id: 1, city: "Sacramento", distance: 88 }
{ _id: 2, city: "Reno", distance: 218 }
{ _id: 3, city: "Los Angeles", distance: 383 }

{ "city" : "San Jose", "Rest stops" : [ 0, 25 ] }
{ "city" : "Sacramento", "Rest stops" : [ 0, 25, 50, 75 ] }
{ "city" : "Reno", "Rest stops" : [ 0, 25, 50, 75, 100, 125, 150, 175, 200 ] }
{ "city" : "Los Angeles", "Rest stops" : [ 0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375 ] }
 threeFavorites: { $slice: [ "$favorites", 3 ]}
 description: { $ifNull: [ "$description", "Unspecified" ] }
 {
          $switch:
            {
              branches: [
                {
                  case: { $gte : [ { $avg : "$scores" }, 90 ] },
                  then: "Doing great!"
                },
                {
                  case: { $and : [ { $gte : [ { $avg : "$scores" }, 80 ] },
                                   { $lt : [ { $avg : "$scores" }, 90 ] } ] },
                  then: "Doing pretty well."
                },
                {
                  case: { $lt : [ { $avg : "$scores" }, 80 ] },
                  then: "Needs improvement."
                }
              ],
              default: "No scores found."
            }
         }
上一篇 下一篇

猜你喜欢

热点阅读