Does querying certain fields only save query time in mongodb query?
Assume I have a schema like shown below.
const CommentSchema = new mongoose.Schema({
commentText:{
type:String,
required: true
},
arrayOfReplies: [{
replyText:{
type:String,
required: true
},
likes: [{
objectIdOfUser: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true,
},
}],
}],
});
I am trying to find out if mongodb queries the whole document then filters it or if the filtering happens inside of mongodb.
If I have a large arrayOfRepliesarray, for example 500,000 replies. Will the query below, as shown the mongoose docs, save query time as compared to querying the whole document?
Comment.findById(id, 'commentText', function (err, comment) {});
EDIT
I had earlier asked with this(see below). I have changed my question to reflect what I really meant to ask. Although the answer for the question with the query below is still there.
Comment.findById(id, 'replyText', function (err, comment) {});