Mongo find() 产生 {} 以及预期的结果



您好,我正在尝试在查询中仅过滤掉video_trim,但代码仍然生成空对象来代替过滤掉的内容

这是代码

const findTrims = (db, cb) => {
    // Get the documents collection
    const collection = db.collection(documentName);
    // Find some documents
    collection.find({}, {projection:{ _id: 0, name: 0, label: 0 }}).toArray((err, docs) => {
      // An error occurred we need to return that to the given 
      // callback function
      if (err) {
        return cb(err);
      }
      assert.equal(err, null);
      console.log("Found the following records");
      console.log(docs)
      return cb(null, docs);
    });
  }
module.exports = {
findTrims: cb => {
    MongoClient.connect(url, (err, client) => {
      if (err) {
        return cb(err)
      }
      console.log('Connected successfully to server')
      const db = client.db(dbName)
      findTrims(db, (err, docs) => {
        if (err) {
          return cb(err)
        }
        // return your documents back to the given callback
        return cb(null, docs)
      })
    })
  }
}

查找的输出是这样的

[ {}, {}, {

}, {}, { Video_trim: ' ' } ]

如何摆脱 {}?

传递一些条件进行筛选。 collection.find({"Video_trim": { $exists: true }}, { _id: 0, name: 0, label: 0 })

最新更新