Closed
Description
I've encountered surprising behavior with schemas that use mongoose.Schema.Types.Array
. The following is a minimal example to demonstrate.
const mongoose = require('mongoose')
const Model = mongoose.model('Foo', {
array1: Array,
array2: mongoose.Schema.Types.Array
})
const item = new Model({
array1: [1,2,3],
array2: [1,2,3]
})
console.log(mongoose.version)
console.log(item)
The output is
5.9.21
{
array1: [ 1, 2, 3 ],
array2: [ [ 1 ], [ 2 ], [ 3 ] ],
_id: 5efe4b84eae249003167a757
}
Notice that array2
, which is specified as a mongoose.Schema.Types.Array
, becomes an array of arrays.
Is this the expected behavior? If so, where is this documented?