marking a populated array modified hangs mongoose #477

Closed
aheckmann opened this Issue Aug 27, 2011 · 5 comments

2 participants

@aheckmann
var Aschema = new Schema({ myrefs: [{ type: Schema.ObjectId, ref: 'Thing' }] });
var A = mongoose.model('A', Aschema);
A.findById(id).populate('myrefs').run(function (err, a) {
  a.myrefs.splice(0, 1);
  a.save(function () {}) // hangs here
})

Just marking myrefs modified will hang it too.

@aheckmann

docs are not getting casted b/c its a MongooseArray instead of a DocumentArray

@eschan

I might be running into a similar issue.

If I have an empty array of embedded document. The populate query for 'comments.user' hangs. It seems to work when the array is not empty. This is kinda of a show stopper for me right now. Is there any work around for the time being?

var comment_schema = new Schema({
    text: String,
    user: { type: ObjectId, ref: 'User' },
    create_date: { type: Date, default: Date.now },
    update_date: { type: Date, default: Date.now }
});

var post_schema = new Schema({
    text: String,
    create_date: { type: Date, default: Date.now },
    update_date: { type: Date, default: Date.now },
    comments: [comment_schema]
});


//Query
db.Post.findById(someid).populate('comments.user').run(function(err, response) {
//HANGS
})
@eschan

I can repo it but adding this test to model.ref.test.js. This creates a BlogPost with an empty comments array. When trying to get the post and populate the commets array... the query will hang.

'test populating subdocuments partially with empty array': function () {

var db = start()
  , BlogPost = db.model('RefBlogPost', posts)
  , User = db.model('RefUser', users);

User.create({
    name  : 'User 1'
  , email : 'user1@learnboost.com'
}, function (err, user1) {
  should.strictEqual(err, null);

  User.create({
      name  : 'User 2'
    , email : 'user2@learnboost.com'
  }, function (err, user2) {
    should.strictEqual(err, null);

    var post = BlogPost.create({
        title: 'Woot'
      , comments: [/*EMPTY ARRAY*/]
    }, function (err, post) {
      should.strictEqual(err, null);

      BlogPost
        .findById(post._id)
        .populate('comments._creator', ['email'])
        .run(function (err, post) {

          should.strictEqual(err, null);

          db.close();
        });
    });
  });
});

}

@aheckmann
@aheckmann

@eschan I opened #481 for this issue

@aheckmann aheckmann closed this in ddd3d32 Aug 28, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment