using $and with $match in mongodb

后端 未结 3 1225
孤街浪徒
孤街浪徒 2020-12-13 04:31

I am trying to use the following query in MongoDB but it is not working.

db.test.aggregate(
$match: {$and: [type: {$in: [\"TOYS\"]}, type: {$nin: [\"BARBIE\"         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 04:34

    $and with $match works just fine.

    You have syntax errors in your query. Try this.

    db.test.aggregate([
                       { 
                         $match: {
                              $and: [ 
                                  {type: {$in: ["TOYS"]}}, 
                                  {type: {$nin: ["BARBIE"]}}, 
                                  {time: {$lt:ISODate("2013-12-09T00:00:00Z")}}
                              ]
                         }
                       }
                      ])
    

    And for what you are trying to do, you do not need an $and.

提交回复
热议问题