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
Copy file name to clipboardExpand all lines: lib/schema.js
+26Lines changed: 26 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2251,6 +2251,32 @@ function _deletePath(schema, name) {
2251
2251
deletebranch[last];
2252
2252
}
2253
2253
2254
+
/**
2255
+
*
2256
+
* @param {String|Array} path The virutal path(s) to remove.
2257
+
* @returns {Schema} the Schema instance, or a mongoose error if the virtual does not exist.
2258
+
* @api public
2259
+
*/
2260
+
2261
+
Schema.prototype.removeVirtual=function(path){
2262
+
if(typeofpath==='string'){
2263
+
path=[path];
2264
+
}
2265
+
if(Array.isArray(path)){
2266
+
for(constvirtualofpath){
2267
+
if(this.virtuals[virtual]==null){
2268
+
thrownewMongooseError(`Attempting to remove virtual "${virtual}" that does not exist.`);
2269
+
}
2270
+
}
2271
+
2272
+
for(constvirtualofpath){
2273
+
deletethis.paths[virtual];
2274
+
deletethis.virtuals[virtual];
2275
+
}
2276
+
}
2277
+
returnthis;
2278
+
};
2279
+
2254
2280
/**
2255
2281
* Loads an ES6 class into a schema. Maps [setters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set) + [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get), [static methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static),
2256
2282
* and [instance methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Class_body_and_method_definitions)
0 commit comments