我在使用 MongoDB Atlas Server 時遇到了這個錯誤...這是什么意思...?有人可以用簡單的話解釋一下嗎...
這是我正在嘗試的查詢......
db.posts.find({}, {title: 1, date: 0})
posts在資料庫中的結構如下:
[
{
_id: ObjectId("63739044de169f6d0h2e6a3d"),
title: 'Post 2',
body: 'a news post',
category: 'News',
likes: 1,
tags: [ 'news', 'events' ],
date: 'Tue Nov 15 2022 18:53:24 GMT 0530 (India Standard Time)'
},
{
_id: ObjectId("63739271de179f5d0e31e5b2"),
title: 'Post 1',
body: 'hey there, hemant here',
category: 'random',
likes: 1,
tags: [ 'random', 'events' ],
date: 'Tue Nov 15 2022 18:41:24 GMT 0530 (India Standard Time)'
}
]
但是我收到一個錯誤,上面寫著......
MongoServerError: Cannot do exclusion on field date in inclusion projection
我試圖獲取除日期引數和標題引數之外的所有檔案物件,但出現錯誤...
uj5u.com熱心網友回復:
根據檔案,第一個引數find是 filter ,第二個是projection. projection允許您指定要回傳的欄位。_id是您需要在投影中明確排除的唯一欄位。對于所有其他欄位,您只需說明包含內容。您將必須遵循以下格式。
db.posts.find({}, {title: 1, body:1, category:1, likes:1, tags:1})
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/535350.html
