Reputation: 777
Hello I am trying to filter out for only video_trim in my query but the code still produces empty objects in the place of filtered out content
here is the code
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)
})
})
}
}
the output of the find is this
[ {}, {}, {}, {}, { Video_trim: ' ' } ]
How do I get rid of the {}?
Upvotes: 0
Views: 30
Reputation: 132
Pass some conditions to filter. f.e. collection.find({"Video_trim": { $exists: true }}, { _id: 0, name: 0, label: 0 })
Upvotes: 1