LearnBoost/mongoose — comment on commit 389ac3aa625a58c176d048f9da1bb1958609d3b9
File:  line 0
By gitfy:

The problem with above setting is "branch[last] = obj", it make the tree as well as the path structure set with same object reference.

If you go ahead add additional properties to the schema to that path later, this affects the schema definition object as well.

I have a scenario, where i define a custom schema type. The custom schema type, adds some properties to the schema using a plugin. Due to the above change, when i add more properties to the schema, this changes the options also with which the schema-type was originally instantiated.

If this is the intended behavior, during the time when the schema-type is getting created, the options should be cloned.

Example :
new Schema({
a : { type : 'custom-type' }
});

In the plugin, for any custom-type definition, certain additional properties are added
schema.add({ prop : 'string } , path);

At this point, the schema definition option { type : 'custom-type' } is also getting modified with the properties that are added. Which is a side-effect due the above change, where the references are shared.
Because the above change assumes a : { type : 'custom-type' } as an embedded definition, but it just a regular type definition.