Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single nested schema update objects nonfunctional with mixed object and path #3820

Closed
btkostner opened this issue Jan 29, 2016 · 1 comment
Closed
Milestone

Comments

@btkostner
Copy link

I'll let the code do the talking. Here is a shortened version for testing:

var child = new mongoose.Schema({
  item2: {
    item3: String,
    item4: String,
  },
});

var parent = new mongoose.Schema({
  name: String,
  item1: child,
});

var Parent = mongoose.model('Parent', parent)

mongoose.connect('mongodb://localhost/tmp', function(err) {
  Promise.resolve(Parent.create({
    'name': 'The first of its kind',
  }))
  .then(function(doc) {
    return doc.update({
      'item1.item2': {
        'item3': 'Test1',
        'item4': 'Test2',
      },
    });
  })
  .then(function(data) {
    console.log(data) // { ok: 0, n: 0, nModified: 0 }
  })
});

If doc.update() is changed to something like below, then all goes according to plan.

    return doc.update({
      'item1.item2.item3': 'Test1',
      'item1.item2.item4': 'Test2',
    });

Node: v5.5.0
Mongo: 3.2.0
Mongoose: 4.3.7
Time to find issue: > 3 hours

@btkostner
Copy link
Author

I realize that according to mongodb, you have to use dot notation for this, but it would be nice if mongoose would convert it to dot notation for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants