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

Open
jessefulton opened this Issue Mar 4, 2014 · 1 comment

Projects

None yet

2 participants

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);
      });
    })

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