投影不适用于查找查询

fil*_*zyk 4 mongodb node.js

您好,我想通过查询排除一些字段。我正在使用 nodejs

public async getDoc() {
        return new Promise((resolve, reject) => {
            this.database.collection('users').find({email: "value3"}, {password: 0}).toArray((err, result) => {
                if(err) {
                    reject(err)
                }
                resolve(result);
            });
        })
    }
Run Code Online (Sandbox Code Playgroud)

但在结果集中我不断收到密码字段..

Ash*_*shh 11

投影不适用于新的 nodejs mongodb 驱动程序......相反,您必须在.project()此处使用游标方法

this.database.collection('users')
  .find({ "email": "value3" })
  .project({ "password": 0 })
  .toArray();
Run Code Online (Sandbox Code Playgroud)