I want to search some collection that had a specific field in MongoDB. Say there is two collection that had a name field and the other not.
Using mongoose.js though I found someone asks this, now the answer is outdated. How to do that with nowadays mongoose versions?
Here the code that I tried, I'm successfully getting all the collections name but when I search for the specific fields it doesn't work and gave me no error.
mongoose.connection.db.listCollections().toArray((error, collections) => {
collections.forEach( (collection) => {
var collectionName = mongoose.connection.db.collection(collection.name)
var count = collectionName.find({ "duck_name": { $exists: true }}).count()
if ( count > 0 ){
console.log(collection.name)
}
})
})
There is no error and no warnings on that code.