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 have a pre-existing module for cloning a schema which is used to back up web pages (like a CMS system). When I upgraded to mongoose 5.7.5 (from 5.5.2), the schema cloning broke.
this is the cloning module:
module.exports = function (schema, mongoose) {
'use strict';
mongoose = mongoose || require('mongoose');
let clonedSchema = new mongoose.Schema();
schema.eachPath(function (key, path) {
if (key === '_id') {
return;
}
let clonedPath = {};
clonedPath[key] = path.options;
delete clonedPath[key].unique;
clonedSchema.add(clonedPath);
});
return clonedSchema;
};
It's breaking on clonedSchema.add(clonedPath) with the first path it tries to add.
ERROR
UnhandledPromiseRejectionWarning: MongooseError: Invalid ref at path "title". Got null
at new MongooseError (/node_modules/mongoose/lib/error/mongooseError.js:10:11)
at validateRef (/node_modules/mongoose/lib/helpers/populate/validateRef.js:17:9)
at Clone.Schema.path (/node_modules/mongoose/lib/schema.js:577:5)
at Clone.add (/node_modules/mongoose/lib/schema.js:442:12)
at Schema.extend (/node_modules/mongoose-schema-extend/index.js:81:13)
at /api/common/lib/clone-schema.js:19:22
at Schema.eachPath (/api/node_modules/mongoose/lib/schema.js:934:5)
at module.exports (/api/common/lib/clone-schema.js:9:12)
at Object.<anonymous> (/api/common/schemas/Page.schema.js:39:23)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
I did a comparison of the schema passed into this module between mongoose 5.5.2 and 5.7.5. The only difference in 5.7.5 is that $immutable is now an included property
I tried "npm mongoose-schema-extend", but that gave me TypeError: Method Map.prototype.has called on incompatible receiver [object Map]. So not sure how to use it here.
const extend = require('mongoose-schema-extend');
let clonedSchema = new mongoose.Schema();
schema.eachPath(function (key, path) {
if (key === '_id') {
return;
}
let prop = {};
prop[key] = path;
clonedSchema.extend(prop);
});
I threw a try/catch into the module to see if that would do anything. Nope.
I also deleted the node_modules directory and re-installed the plugins.
I also added useUnifiedTopology: true to Mongoose initialization for posterity.
Does anyone know what changed in 5.7 to break this?
The text was updated successfully, but these errors were encountered:
BUG
Using
I have a pre-existing module for cloning a schema which is used to back up web pages (like a CMS system). When I upgraded to mongoose 5.7.5 (from 5.5.2), the schema cloning broke.
this is the cloning module:
this is the schema getting cloned
It's breaking on
clonedSchema.add(clonedPath)
with the first path it tries to add.ERROR
I did a comparison of the
schema
passed into this module between mongoose 5.5.2 and 5.7.5. The only difference in 5.7.5 is that$immutable
is now an included propertyI tried "npm mongoose-schema-extend", but that gave me
TypeError: Method Map.prototype.has called on incompatible receiver [object Map]
. So not sure how to use it here.I threw a try/catch into the module to see if that would do anything. Nope.
I also deleted the node_modules directory and re-installed the plugins.
I also added
useUnifiedTopology: true
to Mongoose initialization for posterity.Does anyone know what changed in 5.7 to break this?
The text was updated successfully, but these errors were encountered: