Mongodb $lookup Not working with _id

后端 未结 7 2265
猫巷女王i
猫巷女王i 2020-12-31 09:43

wend try with this query, return the lookup is empty

db.getCollection(\'tests\').aggregate([
    {$match: {typet:\'Req\'}},
    {$project: {incharge:1}},
            


        
7条回答
  •  心在旅途
    2020-12-31 10:25

    I finaly found the solution, is a problem with my Schema in mongoose with the ObjectId

    I change this

    var Schema = new Schema({
        name: { type: String, required: true},
        incharge: { type: String, required: true},
    });
    

    with this

    var Schema = new Schema({
        name: { type: String, required: true},
        incharge: { type: mongoose.Schema.ObjectId, required: true},
    });
    

    and is working

提交回复
热议问题