Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

dot notation does not work on Mixed types when creating new document #1946

Open
jessefulton opened this Issue · 1 comment

2 participants

Jesse Fulton sharkboy1976
Jesse Fulton

When trying to create a new document with nested properties using dot notation, it fails if the nested property is within a "Mixed" type. Dot notation works with more strict nested definitions, I'd expect it to work with mixed as well? I added the following tests to model.create.test.js:

This one passes (setting mix.val using a nested object):

    it('works when explicitly generating mixed obj', function(done){
      var schema2 = Schema({ name:String, mix: { type: Schema.Types.Mixed }, nested: {prop: String} });
      var M = db.model('model-create-M', schema2, 'model-create-'+random());
      var m1 = new M({"name": "test", "mix": {"val": "foo"}, "nested.prop": "bar"});
      assert.equal("test", m1.name);
      assert.equal("foo", m1.mix.val);
      assert.equal("bar", m1.nested.prop);
      m1.save(function(err, doc) {
        if (err) {
          return done(err);
        }
        assert.equal("test", doc.name);
        assert.equal("foo", doc.mix.val);
        done(err);
      });
    })

And the following fails (setting mix.val using dot notation):

    it('works when passing dot notation to mixed property', function(done){
      var schema2 = Schema({ name:String, mix: { type: Schema.Types.Mixed }, nested: {prop: String} });
      var M = db.model('model-create-M', schema2, 'model-create-'+random());
      var m1 = new M({"name": "test", "mix.val": "foo", "nested.prop": "bar"});
      assert.equal("test", m1.name);
      assert.equal("foo", m1.mix.val);
      assert.equal("bar", m1.nested.prop);
      m1.save(function(err, doc) {
        if (err) {
          return done(err);
        }
        assert.equal("test", doc.name);
        assert.equal("foo", doc.mix.val);
        done(err);
      });
    })
sharkboy1976

in schema the property val is not defined in mix, therefore the dot notation doesn't work, whereas mix can handle an object as value.

mongoose handles this correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.