RangeError: Maximum call stack size exceeded when backing up multiple schemas in Mongoose?

Hello!
Implement f-onal with the addition of "other" in the schema Mongoose. Here is the code for the POST route :

Router.route("/confirm_friend").post(function(req, res) {
 UserSchema.findOne({ _id: req.body.self }).then(
 (self) => {
 UserSchema.findOne({ _id: req.body.whom }).then(
 (whom) => {
self.friends.push(whom)
whom.friends.push(self);
 self.requests.splice(self.requests.indexOf(whom), 1);
self.save();
whom.save();
Res. send("success");
},
 (err) => {
Res. send(err);
 console.log("--- err", err);
},
);
},
 (err) => {
 console.log("--- err", err);
},
);
});


As you can see from the code, I get two id, self and whom, based on them looking for users in the database, delete the element from requests and add friends. Alas, getting this error :

function cloneObject(obj, options) {
^

RangeError: Maximum call stack size exceeded
at cloneObject (/Users/shchypylov/Documents/projects/personal/social/node_modules/mongoose/lib/utils.js:249:21)
at clone (/Users/shchypylov/Documents/projects/personal/social/node_modules/mongoose/lib/utils.js:183:16)
at cloneObject (/Users/shchypylov/Documents/projects/personal/social/node_modules/mongoose/lib/utils.js:257:11)
at clone (/Users/shchypylov/Documents/projects/personal/social/node_modules/mongoose/lib/utils.js:183:16)
at cloneObject (/Users/shchypylov/Documents/projects/personal/social/node_modules/mongoose/lib/utils.js:257:11)
at clone (/Users/shchypylov/Documents/projects/personal/social/node_modules/mongoose/lib/utils.js:183:16)
at cloneObject (/Users/shchypylov/Documents/projects/personal/social/node_modules/mongoose/lib/utils.js:257:11)
at clone (/Users/shchypylov/Documents/projects/personal/social/node_modules/mongoose/lib/utils.js:183:16)
at cloneObject (/Users/shchypylov/Documents/projects/personal/social/node_modules/mongoose/lib/utils.js:257:11)
at clone (/Users/shchypylov/Documents/projects/personal/social/node_modules/mongoose/lib/utils.js:183:16)
at cloneObject (/Users/shchypylov/Documents/projects/personal/social/node_modules/mongoose/lib/utils.js:257:11)
at clone (/Users/shchypylov/Documents/projects/personal/social/node_modules/mongoose/lib/utils.js:183:16)
at cloneObject (/Users/shchypylov/Documents/projects/personal/social/node_modules/mongoose/lib/utils.js:257:11)
at clone (/Users/shchypylov/Documents/projects/personal/social/node_modules/mongoose/lib/utils.js:183:16)
at cloneObject (/Users/shchypylov/Documents/projects/personal/social/node_modules/mongoose/lib/utils.js:257:11)
at clone (/Users/shchypylov/Documents/projects/personal/social/node_modules/mongoose/lib/utils.js:183:16)


How to treat it?
Thank you
June 3rd 19 at 19:05
0 answer

Find more questions by tags Node.jsMongooseExpress.jsMongoDB