mongoose-gridfs icon indicating copy to clipboard operation
mongoose-gridfs copied to clipboard

Add virtual to schema

Open andreamatt opened this issue 4 years ago • 0 comments

Is it possible to modify the attachment schema to add a virtual? I tried adding an "id" virtual (simply returns this._id). It manages to get the correct id but returns undefined when called.

gridFSbucket.schema.virtual("id").get(function(){
	console.log("Called virtual get on " + this._id); // correct id
	return this._id; // when called i get undefined
});

andreamatt avatar Feb 22 '21 18:02 andreamatt