Suppose I have a document for example: var doc = Model.findOne({name:”name”});
Now if the document gets edited trough another connection the the database, doc doesn’t hold the right information. I do need it, so I have to “refresh” or “redownload” it from the database. Is there any way to do this with only the object “doc”?
Assuming
doccontains the document instance to refresh, you can do this to generically refresh it:However, it’s better to not persist/cache Mongoose document instances beyond your immediate need for them. Cache the immutable
_idof docs you need to quickly access, not the docs themselves.