-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Description
Do you want to request a feature or report a bug?
bug
What is the current behavior?
define a Schema like below
const Group = new mongoose.Schema({
title: {
type: String,
required: true
},
members: {
type: [
{ type: SchemaTypes.ObjectId, ref: 'User' }
],
default: []
},
owner: {
type: SchemaTypes.ObjectId,
ref: 'User',
required: true
},
managers: {
type: [{
type: SchemaTypes.ObjectId,
ref: 'User'
}],
/* type: String works fine but not type: [String] */
default: function() {
console.log('this:',this === global);
return [this.owner];
}
}
})
then create a document
const g = new Group({
title: 'test',
owner: users[0]._id,
});
the document's members
property is [ undefined ]
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
'this' should be the document itself, but this === global
is true
Please mention your node.js, mongoose and MongoDB version.
nodejs v9.8.0 (Windows)
mongoose 5.0.11
mongoDB runs on Azure Cosmos DB maybe ^v3.4
Metadata
Metadata
Assignees
Labels
No labels