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 MongooseArray
s, but if told I wouldn't mind putting together the appropriate PR. Let me know if you need additional information.
Thanks!
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:
Most helpful comment
Whoa that's a bad bug, will fix ASAP