我有一個查找查詢,在其中我使用包含投影來過濾出已發布 = false 的帖子。我還需要排除一個欄位,但考慮到包含投影,我無法鍛煉如何去做。
這是我的聚合:
{
...
'$lookup': {
'from': 'photos',
'localField': '_id',
'foreignField': 'postId',
'as': 'photoData'
}
}, {
'$project': {
'_id': 1,
'field1': 1,
'field2': 1,
'field3': 1,
'photoData': {
'_id': 0, // ** I am trying to exclude this field **
'$filter': {
'input': '$photoData',
'as': 'photo',
'cond': {
'$ne': [
'$$photo.published', false
]
}
}
}
}
我正在嘗試在 photoData 查找中排除“_id”欄位。使用 photoData 投影中的 '_id: 0' 這樣做會給出“不能在包含投影中的欄位 _id 上進行排除”。我也嘗試了其他一些方法,但都沒有成功。有沒有辦法做到這一點?
uj5u.com熱心網友回復:
您可以使用此階段洗掉欄位:
{ $unset: "photoData._id" }
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/410943.html
標籤:
上一篇:SpringBatch在H2的SQL陳述句中創建語法錯誤
下一篇:插入資料的貓鼬觸發器
