Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why do Array and mongoose.Schema.Types.Array behave differently? #9194

Closed
jgraydus opened this issue Jul 2, 2020 · 0 comments
Closed

Why do Array and mongoose.Schema.Types.Array behave differently? #9194

jgraydus opened this issue Jul 2, 2020 · 0 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@jgraydus
Copy link

jgraydus commented Jul 2, 2020

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?

@vkarpov15 vkarpov15 added this to the 5.9.22 milestone Jul 4, 2020
@vkarpov15 vkarpov15 added has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Jul 4, 2020
vkarpov15 added a commit that referenced this issue Jul 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

2 participants