Mongoose: 4.6.4 regression - MongooseArray now simply Array

Created on 25 Oct 2016  路  5Comments  路  Source: Automattic/mongoose

This change https://github.com/Automattic/mongoose/commit/687eecde0c1564b873b8e3c0651f1066c47c3379 now always returns instances of Array whereas before it could sometimes return instances of MongooseArray when populating, depending on the value of val. This introduces problems/crashes wherever a MongooseArray is expected in a result, such as when doing .toObject() on fields of a returned Document.

I don't know what is the clean way of cloning MongooseArrays, but if told I wouldn't mind putting together the appropriate PR. Let me know if you need additional information.

Thanks!

Most helpful comment

Whoa that's a bad bug, will fix ASAP

All 5 comments

Whoa that's a bad bug, will fix ASAP

Actually @mathieumg can you clarify which situations it would return a MongooseArray? I don't see any instances like that in our test cases...

const demoSchema = new Schema({
  demo: [{
    type: String,
    ref: "Demo"
  }],
});

Then populated this way:

Demo
.findOne({_id: "someid"})
.exec(doc => doc.populate({
  path: "demo",
  select: "somefield",
  model: "Demo",
}));

Fixed in master, will be released with 4.6.6 :+1:

So that's how you copy a MongooseArray! :) Thanks for the quick fix. :tada:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lukasz-zak picture lukasz-zak  路  3Comments

simonxca picture simonxca  路  3Comments

ArThoX picture ArThoX  路  3Comments

gustavomanolo picture gustavomanolo  路  3Comments

Soviut picture Soviut  路  3Comments