You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having the following issue which is this resurfaced issue but with the latest mongoose version 4.9.4
/home/user/Desktop/node_modules/mongoose/lib/types/embedded.js:87
this.__parentArray._markModified();
^
TypeError: this.__parentArray._markModified is not a function
at EmbeddedDocument.markModified (/home/user/Desktop/node_modules/mongoose/lib/types/embedded.js:87:24)
at SingleNested.Subdocument.markModified (/home/user/Desktop/node_modules/mongoose/lib/types/subdocument.js:62:18)
at SingleNested.Document.$__set (/home/user/Desktop/node_modules/mongoose/lib/document.js:874:10)
at SingleNested.Document.set (/home/user/Desktop/node_modules/mongoose/lib/document.js:785:10)
at SingleNested._handleIndex (/home/user/Desktop/node_modules/mongoose/lib/document.js:625:14)
at SingleNested.Document.set (/home/user/Desktop/node_modules/mongoose/lib/document.js:585:24)
at SchemaType.Embedded.cast (/home/user/Desktop/node_modules/mongoose/lib/schema/embedded.js:132:12)
at SchemaType.getDefault (/home/user/Desktop/node_modules/mongoose/lib/schematype.js:616:23)
at EmbeddedDocument.Document.$__buildDoc (/home/user/Desktop/node_modules/mongoose/lib/document.js:265:22)
at EmbeddedDocument.Document (/home/user/Desktop/node_modules/mongoose/lib/document.js:61:20)
at EmbeddedDocument [as constructor] (/home/user/Desktop/node_modules/mongoose/lib/types/embedded.js:31:12)
at new EmbeddedDocument (/home/user/Desktop/node_modules/mongoose/lib/schema/documentarray.js:70:17)
at DocumentArray.SchemaArray (/home/user/Desktop/node_modules/mongoose/lib/schema/array.js:67:21)
at new DocumentArray (/home/user/Desktop/node_modules/mongoose/lib/schema/documentarray.js:31:13)
at Function.Schema.interpretAsType (/home/user/Desktop/node_modules/mongoose/lib/schema.js:618:14)
at Schema.path (/home/user/Desktop/node_modules/mongoose/lib/schema.js:563:29)
The code is the following
"use strict";
var mongoose = require('mongoose');
var db = mongoose.createConnection("mongodb://localhost:27017/testDB");
let RatingsItemSchema = new mongoose.Schema({
id: Number,
value: Number,
_id: false
});
let RatingsItem = db.model('RatingsItem', RatingsItemSchema);
let RatingsSchema = new mongoose.Schema({
ratings: {
type: RatingsItemSchema,
default:
{ id: 1, value: 0 }
},
_id: false
});
let RestaurantSchema = new mongoose.Schema({
ratings: {
type: [RatingsItemSchema],
default: [
{ id: 1, value: 0 },
{ id: 2, value: 0 },
{ id: 3, value: 0 },
{ id: 4, value: 0 },
{ id: 5, value: 0 }
]
},
menu: {
type: [RatingsSchema]
}
});
let Ratings = db.model('Ratings', RatingsSchema);
let Restaurant = db.model('Restaurant', RestaurantSchema);
var rest = new Restaurant();
rest.menu.push(new Ratings());
console.log(JSON.stringify(rest, null, 2));
Version
mongoose 4.9.4
mongodb 3.4.2
node 5.10.0
The workaround specified in the beginning of referenced issue fix this issue (adding || !this.__parentArray._markModified to the prototype in node_modules/mongoose/lib/types/embedded.js)
Furthermore, I've discovered the issue caused another issue (not sure if thats a separate issue), I have got the following error
/home/user/Desktop/node_modules/mongoose/lib/schema/documentarray.js:322
throw new CastError('embedded', valueInErrorMessage,
^
CastError: Cast to embedded failed for value "{ id: 5, value: 0 }" at path "ratings"
at MongooseError.CastError (/home/user/Desktop/node_modules/mongoose/lib/error/cast.js:26:11)
at DocumentArray.cast (/home/user/Desktop/node_modules/mongoose/lib/schema/documentarray.js:322:19)
at DocumentArray.SchemaType.getDefault (/home/user/Desktop/node_modules/mongoose/lib/schematype.js:616:23)
at EmbeddedDocument.Document.$__buildDoc (/home/user/Desktop/node_modules/mongoose/lib/document.js:265:22)
at EmbeddedDocument.Document (/home/user/Desktop/node_modules/mongoose/lib/document.js:61:20)
at EmbeddedDocument [as constructor] (/home/user/Desktop/node_modules/mongoose/lib/types/embedded.js:31:12)
at new EmbeddedDocument (/home/user/Desktop/node_modules/mongoose/lib/schema/documentarray.js:70:17)
at DocumentArray.SchemaArray (/home/user/Desktop/node_modules/mongoose/lib/schema/array.js:67:21)
at new DocumentArray (/home/user/Desktop/node_modules/mongoose/lib/schema/documentarray.js:31:13)
at Function.Schema.interpretAsType (/home/user/Desktop/node_modules/mongoose/lib/schema.js:618:14)
at Schema.path (/home/user/Desktop/node_modules/mongoose/lib/schema.js:563:29)
at Schema.add (/home/user/Desktop/node_modules/mongoose/lib/schema.js:445:12)
at new Schema (/home/user/Desktop/node_modules/mongoose/lib/schema.js:99:10)
at Object.<anonymous> (/home/user/Desktop/mongoose.js:38:24)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
Which occurs when I specify a nested array instead of a nested object and setting a default value for this array. The code is the following
I'm having the following issue which is this resurfaced issue but with the latest mongoose version 4.9.4
The code is the following
Version
The workaround specified in the beginning of referenced issue fix this issue (adding
|| !this.__parentArray._markModified
to the prototype innode_modules/mongoose/lib/types/embedded.js
)Furthermore, I've discovered the issue caused another issue (not sure if thats a separate issue), I have got the following error
Which occurs when I specify a nested array instead of a nested object and setting a
default
value for this array. The code is the followingThe text was updated successfully, but these errors were encountered: