Всем привет!
Реализую ф-онал с добавлением "друга" в схему Mongoose. Вот код на 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);
},
);
});
Как видно из кода, я получаю две id,
self и
whom, на их основе ищу юзеров в базе, удаляю элемент из
requests и добавляю в
friends. Увы, получаю данную ошибку :
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)
Как это лечить?
Спасибо