Skip to content
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

Schema.clone() removes prototypes with new Mongoose(). #9426

Closed
chumager opened this issue Sep 17, 2020 · 0 comments
Closed

Schema.clone() removes prototypes with new Mongoose(). #9426

chumager opened this issue Sep 17, 2020 · 0 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@chumager
Copy link

Do you want to request a feature or report a bug?
Bug
What is the current behavior?
If you use Schema.clone(), the functions defined as prototype get removed from cloned schema.
If the current behavior is a bug, please provide the steps to reproduce.

"use strict";
const mongoose = require("mongoose");
const db = new mongoose.Mongoose();
db.Schema.prototype.localTest = function () {
  console.log("prototype");
};
const test = new db.Schema({});
console.log(test.localTest);
const test2 = test.clone();
console.log(test2.localTest);

result:

[Function (anonymous)]
undefined

If you use mongoose directly it works...

Besides this problem I always use new Mongoose() to isolate, is that correct? I need to keep separated different plugins, models and modifications for each mongoose

What is the expected behavior?
To be able to clone schemas and keep the prototype functions.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
node: 14.10.1
mongoose: 5.10.5
mongodb: not even connected.

@vkarpov15 vkarpov15 added this to the 5.10.7 milestone Sep 22, 2020
vkarpov15 added a commit that referenced this issue Sep 22, 2020
@vkarpov15 vkarpov15 added the confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. label Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

2 participants