Я хочу вернуть JSON со всеми указанными c полями объекта в моей коллекции. Но была эта ошибка.
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'ReplSet'
| property 's' -> object with constructor 'Object'
| property 'coreTopology' -> object with constructor 'ReplSet'
| ...
| property 's' -> object with constructor 'Object'
--- property 'topology' closes the circle
Мой путь GET
router.get('/assignments', auth.required, function (req, res, next) {
var user = User.findById(req.payload.id);
var assignments = Assignment.find({ author: user });
// console.log(assignments)
if (!user) { return res.sendStatus(401); }
return res.json({
assignments: assignments.map(function (assignment) {
console.log(assignment)
return assignment.toJSONForTitle();
})
});
});
Моя функция JSON
AssignmentSchema.methods.toJSONForTitle = function(){
return {
title: this.title,
createdAt: this.createdAt,
};
};