Mongoose virtual set function not called when value is an object

I have a mongoose scheme with a virtual mixed type. For instance:

var mongoose = require('mongoose') // version 3.3.1 var FooSchema = new mongoose.Schema( { x: Number } ); FooSchema.virtual('v').set( function(value){ console.log("SETTING", value); }); var Foo = mongoose.model('Foo', FooSchema); new Foo( { v:1 } ); new Foo( { v:[] } ); new Foo( { v:{} } ); 

When I run this code, I get:

 SETTING 1 SETTING [] 

As you will notice, it never shows "SETTING {}", for what reason does this not work?

Github Question Link

+6
source share
1 answer

This was an open issue in Mongoose, which was fixed in a recent commit by Aaron Hekmann .

+1
source

Source: https://habr.com/ru/post/926991/


All Articles