Mongoose provides us lot of methods (findOne
, find
, findByID
, etc.) to find document(s). All these methods return the entire document(s)/model.
Is it possible that when I search for a document, I just return single property from the document/model instead of returning entire document?
Yes, by setting the projection object, which is usually specified right after the criteria object.
Note:
_id
is always included by default, so the only it's exclusion needs to be specified if needed.