求帮助啊 使用connect-mongo的问题 : Converting circular structure to JSON
发布于 11 年前 作者 quyangcode 10901 次浏览 最后一次编辑是 8 年前

代码如下:
var currentUser = req.session.user;
User.getAllAttentionUsers(currentUser.name,function(err,docs){
if(err){
req.flash(‘error’, err);
}
Post.pagePost(null,PAGE_SIZE_DEFAULT,page,function (err, posts) {
if (err) {
posts = [];
}
res.render(‘post’, {
title: ‘首页’,
typeName: ‘首页’,
user: currentUser,
posts: posts
});
});
});

错误如下:
TypeError: Converting circular structure to JSON
at MongoStore.stringify [as _serialize_session] (native)
at MongoStore.module.exports.MongoStore.set (D:\软件\lizi\birdFly\node_modules\connect-mongo\lib\connect-mongo.js:220:40)
at Session.save (D:\软件\lizi\birdFly\node_modules\express\node_modules\connect\lib\middleware\session\session.js:63:25)
at ServerResponse.res.end (D:\软件\lizi\birdFly\node_modules\express\node_modules\connect\lib\middleware\session.js:282:19)
at ServerResponse.res.send (D:\软件\lizi\birdFly\node_modules\express\lib\response.js:152:8)
at res.render.fn (D:\软件\lizi\birdFly\node_modules\express\lib\response.js:756:10)
at View.exports.renderFile [as engine] (D:\软件\lizi\birdFly\node_modules\ejs\lib\ejs.js:317:3)
at View.render (D:\软件\lizi\birdFly\node_modules\express\lib\view.js:76:8)
at Function.app.render (D:\软件\lizi\birdFly\node_modules\express\lib\application.js:506:10) at ServerResponse.res.render (D:\软件\lizi\birdFly\node_modules\express\lib\response.js:760:7) TypeError: Converting circular structure to JSON at Object.stringify (native) at hash (D:\软件\lizi\birdFly\node_modules\express\node_modules\connect\lib\middleware\session.js:352:28) at ServerResponse.end (D:\软件\lizi\birdFly\node_modules\express\node_modules\connect\lib\middleware\session.js:265:34) at ServerResponse.EventEmitter.emit (events.js:92:17) at ServerResponse.res.writeHead (D:\软件\lizi\birdFly\node_modules\express\node_modules\connect\lib\patch.js:73:36) at ServerResponse._implicitHeader (http.js:1132:8) at ServerResponse.OutgoingMessage.end (http.js:921:10) at ServerResponse.module.exports.res.end (D:\软件\lizi\birdFly\node_modules\express\node_modules\connect\lib\middleware\logger.js:148:13) at res.end (D:\软件\lizi\birdFly\node_modules\express\node_modules\connect\lib\middleware\session.js:285:13) at MongoStore.module.exports.MongoStore.set (D:\软件\lizi\birdFly\node_modules\connect-mongo\lib\connect-mongo.js:250:19)

D:\软件\lizi\birdFly\node_modules\express\node_modules\connect\lib\middleware\session.js:352 return crc32.signed(JSON.stringify(sess, function(key, val){ ^ TypeError: Converting circular structure to JSON at Object.stringify (native) at hash (D:\软件\lizi\birdFly\node_modules\express\node_modules\connect\lib\middleware\session.js:352:28) at ServerResponse.end (D:\软件\lizi\birdFly\node_modules\express\node_modules\connect\lib\middleware\session.js:265:34) at ServerResponse.EventEmitter.emit (events.js:92:17) at ServerResponse.res.writeHead (D:\软件\lizi\birdFly\node_modules\express\node_modules\connect\lib\patch.js:73:36) at ServerResponse._implicitHeader (http.js:1132:8) at ServerResponse.OutgoingMessage.end (http.js:921:10) at module.exports.error.message (D:\软件\lizi\birdFly\node_modules\express\node_modules\connect\lib\middleware\errorHandler.js:64:17) at fs.js:266:14 at Object.oncomplete (fs.js:107:15)

代码修改为以下 则正常:
var currentUser = req.session.user;
// User.getAllAttentionUsers(currentUser.name,function(err,docs){
// if(err){
// req.flash(‘error’, err);
// }
Post.pagePost(null,PAGE_SIZE_DEFAULT,page,function (err, posts) {
if (err) {
posts = [];
}
res.render(‘post’, {
title: ‘首页’,
typeName: ‘首页’,
user: currentUser,
posts: posts
});
});
// });

2 回复

为什么没人啊?难道大家都没出现过这个问题,还是什么原因?求大神帮助啊

问题解决了,感谢大家的“帮助”哈

回到顶部