-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Array default bug #5780
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
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Comments
Thanks for reporting, will investigate ASAP |
yup this looks like a bug: const mongoose = require('mongoose');
const co = require('co');
mongoose.Promise = global.Promise;
const GITHUB_ISSUE = `gh-5780`;
exec()
.then(() => {
console.log('successfully ran program');
process.exit(0);
})
.catch(error => {
console.error(`Error: ${error}\n${error.stack}`);
});
function exec() {
return co(function* () {
yield mongoose.connect(`mongodb://localhost:27017/${GITHUB_ISSUE}`, { useMongoClient: true })
const schema = new mongoose.Schema({
permissions: {
type: [[Number]],
default: [[0, 1]]
},
});
const Model = mongoose.model('Model', schema);
console.log(new Model({ }));
});
} the log output:
|
As a workaround do this: const schema = new mongoose.Schema({
permissions: {
type: [[Number]],
default: () => [[0, 1]]
},
}); Something is wrong with the way nested array defaults get casted, but using a function rather than an array as the default seems to avoid this issue. We'll fix this issue ASAP but till then just use the workaround 👍 |
@vkarpov15 Thank you very much!!! Great!!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
bug
What is the current behavior?
I set like this.
But the result default is this:
I want this:
node.js mongoose and MongoDB is the latest version.
The text was updated successfully, but these errors were encountered: