Skip to content

Instantly share code, notes, and snippets.

@vanya2h
Created September 7, 2018 17:28
Show Gist options
  • Save vanya2h/8bc845358a16311064d4ef51cb2671bf to your computer and use it in GitHub Desktop.
Save vanya2h/8bc845358a16311064d4ef51cb2671bf to your computer and use it in GitHub Desktop.
var Parent = mongoose.model('Parent', parentSchema);
var parent = new Parent({ children: [{ name: 'Matt' }, { name: 'Sarah' }] })
parent.children[0].name = 'Matthew';
// `parent.children[0].save()` is a no-op, it triggers middleware but
// does **not** actually save the subdocument. You need to save the parent
// doc.
parent.save(callback);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment