Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Added additional check when creating object from model with emded object... #859

wants to merge 3 commits into from

2 participants


Fix for error when loading model with emded document.

For example if we have such schema

var UserSchema = new Schema({
    user_id: Number,
    location: {
        city: {type: String, 'default': 'New York'},
        country: {type: String, 'default': 'USA'}

and we will load document from database with such data

    user_id: 10,
    location: {city: "Washington"}

we will got broken object. When we will try to get country of such user we will get undefined value.


please add a regression test in


run tests with

make test
@aheckmann aheckmann closed this in e38412b

merged. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 24, 2012
  1. @agnek
  2. @agnek

    Removed bad indention

    agnek authored
  3. @agnek

    Spaces aligned

    agnek authored
This page is out of date. Refresh to see the latest.
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/document.js
4 lib/document.js
@@ -220,7 +220,9 @@ function init (self, obj, doc, prefix) {
if (!schema && obj[i] && 'Object' === obj[i] {
// assume nested object
- doc[i] = {};
+ if (!doc[i]) {
+ doc[i] = {};
+ }
init(self, obj[i], doc[i], path + '.');
} else {
if (obj[i] === null) {
Something went wrong with that request. Please try again.