我正在使用MongoDBMap集服务器...遇到了这个错误...这是什么意思...?有人能用简单的话解释一下吗?
这就是我所尝试的查询...
db.posts.find({}, {title: 1, date: 0})
数据库中的员额结构如下:
[
{
_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
我试图获取除日期参数和包括标题参数之外的所有文档对象,但得到了一个错误...
1条答案
按热度按时间dohp0rv51#
根据文档,
find
中的第一个参数是filter,第二个参数是projection
。projection
允许您指定要返回的字段。_id
是您需要在投影中明确排除的唯一字段。对于所有其他字段,您只需要声明包含。您必须遵循以下格式。