Mongodb $lookup Not working with _id

后端 未结 7 2233
猫巷女王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:19

    Your lookup query is perfect, but the problem is you are storing incharge as string into the db, whereas the _id : ObjectId('theID') is an Object and not just string and you cannot compare a string (' ') with an object ({ }). So, the best way is to store the incharge key as an object(mongoose.Schema.ObjectId) and not as string in the schema.

提交回复
热议问题