Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongoose.js: is it possible to know if field was populated

Tags:

mongoose

I have a document with objectId reference field that can be populated.

Is there a known way to know if the field was already populated?

like image 272
WHITECOLOR Avatar asked Apr 26 '14 13:04

WHITECOLOR


1 Answers

You could use the document.populated(path) method (as documented here). It returns the _id used for population, and undefined if the field has not been populated.

like image 109
matthewtole Avatar answered Oct 09 '22 17:10

matthewtole