Mongo shell is a JavaScript shell, so most standard JavaScript methods are supported. You can check if there is a property that you would do on any normal object in JavaScript - using the hasOwnProperty () method :
db.testData.find({}).forEach(function(x){
if (x.hasOwnProperty('name')) {
}
})
source
share