如果不是,则在内部查找

时间:2019-05-29 10:05:53

标签: mongodb mongodb-query

我想对条件是否适用进行查找     如果有条件,例如如果发生此事件,则查找其他:无     这是我在做什么条件,如果观察到的id是id,则查找其他30     db.Observation.aggregate([     {     “ $ match”:{         “ $ expr”:{              '$ cond':{                   如果:{观察到的对象:对象的ID(“ 5c9147fa7d6fab001868ea48”)},                       然后: {                           管道:[                               {'$ lookup':{                                     来自:“用户”,                                     localField:“ observedId”,                                     foreignField:“ _ id”,                                     作为:“列”                                    }                                }                              ]                             },                           否则:30                          }                        }                      }                    },                  ])`

error message


{
    "$clusterTime" : {{
    "$clusterTime" : {
        "clusterTime" : {
            "_bsontype" : "Timestamp",
            "high_" : 1559122664,
            "low_" : 1
        },
        "signature" : {
            "hash" : {
                "_bsontype" : "Binary",
                "buffer" : {
                    "type" : "Buffer",
                    "data" : [
                        249,
                        159,
                        197,
                        237,
                        245,
                        199,
                        27,
                        38,
                        101,
                        53,
                        183,
                        66,
                        117,
                        244,
                        163,
                        51,
                        65,
                        55,
                        133,
                        70
                    ]
                },
                "position" : 20,
                "sub_type" : 0
            },
            "keyId" : {
                "_bsontype" : "Long",
                "high_" : 1549455967,
                "low_" : 1
            }
        }
    },
    "code" : {
        "_bsontype" : "Int32",
        "value" : 168
    },
    "codeName" : "InvalidPipelineOperator",
    "errmsg" : "Unrecognized expression '$lookup'",
    "message" : "Unrecognized expression '$lookup'",
    "name" : "MongoError",
    "ok" : {
        "_bsontype" : "Double",
        "value" : 0
    },
    "operationTime" : {
        "_bsontype" : "Timestamp",
        "high_" : 1559122664,
        "low_" : 1
    },
    "stack" : "MongoError: Unrecognized expression '$lookup'" +
              "at Function.MongoError.create (/opt/mongobooster/resources/app.asar/node_modules/mongodb-core/lib/error.js:31:11)" +
              "at queryCallback (/opt/mongobooster/resources/app.asar/node_modules/mongodb-core/lib/cursor.js:213:36)" +
              "at /opt/mongobooster/resources/app.asar/node_modules/mongodb-core/lib/connection/pool.js:455:18" +
              "at _combinedTickCallback (internal/process/next_tick.js:67:7)" +
              "at process._tickCallback (internal/process/next_tick.js:98:9)"
}
        "clusterTime" : {
            "_bsontype" : "Timestamp",
            "high_" : 1559122664,
            "low_" : 1
        },
        "signature" : {
            "hash" : {
                "_bsontype" : "Binary",
                "buffer" : {
                    "type" : "Buffer",
                    "data" : [
                        249,
                        159,
                        197,
                        237,
                        245,
                        199,
                        27,
                        38,
                        101,
                        53,
                        183,
                        66,
                        117,
                        244,
                        163,
                        51,
                        65,
                        55,
                        133,
                        70
                    ]
                },
                "position" : 20,
                "sub_type" : 0
            },
            "keyId" : {
                "_bsontype" : "Long",
                "high_" : 1549455967,
                "low_" : 1
            }
        }
    },
    "code" : {
        "_bsontype" : "Int32",
        "value" : 168
    },
    "codeName" : "InvalidPipelineOperator",
    "errmsg" : "Unrecognized expression '$lookup'",
    "message" : "Unrecognized expression '$lookup'",
    "name" : "MongoError",
    "ok" : {
        "_bsontype" : "Double",
        "value" : 0
    },
    "operationTime" : {
        "_bsontype" : "Timestamp",
        "high_" : 1559122664,
        "low_" : 1
    },
    "stack" : "MongoError: Unrecognized expression '$lookup'" +
              "at Function.MongoError.create (/opt/mongobooster/resources/app.asar/node_modules/mongodb-core/lib/error.js:31:11)" +
              "at queryCallback (/opt/mongobooster/resources/app.asar/node_modules/mongodb-core/lib/cursor.js:213:36)" +
              "at /opt/mongobooster/resources/app.asar/node_modules/mongodb-core/lib/connection/pool.js:455:18" +
              "at _combinedTickCallback (internal/process/next_tick.js:67:7)" +
              "at process._tickCallback (internal/process/next_tick.js:98:9)"
}
"$match": {
    "$expr": {
         '$cond': {
              if: { observedId:ObjectId("5c9147fa7d6fab001868ea48")},
                  then: {
                      pipeline:[
                          {'$lookup': {
                                from: "user",
                                localField: "observedId",
                                foreignField: "_id",
                                as: "clumn"
                               }
                           }
                         ]
                        },
                      else: 30,
                     }
                   }
                 }
               },
             ])```

0 个答案:

没有答案