在简单查询中将循环结构转换为json错误
converting circular structure to json error on simple query
我有一个非常简单的应用程序,现在允许您创建一个帐户,并将文档添加到数据库中。当我尝试查询信息并使用res.send()
将其发送回时,它错误地说converting circular structure to JSON
。这是什么意思?文档中的所有对象都是字符串。没有什么特别的。
这是它出错的路线:
var express = require('express');
var router = express.Router();
var cookieParser = require('cookie-parser');
/* GET users listing. */
router.get('/', function(req, res, next) {
// res.send(req.params);
});
router.post('/', function(req, res, next) {
console.log(req.body.nickname + " from the " + req.body.grade + " class registered.");
db.collection('users').insert({email: req.body.email, password: req.body.password, nickname: req.body.nickname, grade: req.body.grade}, function(err, result) {});
res.cookie("fss-sched-account", req.body.email);
res.cookie("fss-sched-password", req.body.password);
console.log(db.collection('users').find({}));
res.json(db.collection('users').find({}));
});
router.get('/nocookies', function(req, res, next) {
});
module.exports = router;
这里是我所有代码的链接:Github
这意味着您正试图从.find()
传递"光标"而不是"结果"。您可能只需要:
db.collection('users').find({}).toArray(err,results) {
if (err) throw err; // or handle somehow
console.log(results);
res.json(results);
})
其中.toArray()
转换为数组以及执行查询,返回您实际可以使用的数据形式。
相关文章:
- 转换 JSON 日期,不考虑时区
- 转换 JSON 文件
- 使用正则表达式转换 JSON 密钥值
- 如何通过javascript转换JSON中的DC2type:数组和DC2type中的JSON
- 转换json中的整数值
- 转换JSON架构格式
- 转换JSON "/日期(1404860400000)"到javascript日期
- 在js中转换json数组
- 检索原始日期值转换JSON.stringify
- Java脚本转换json数据
- 用JS转换JSON字符串
- 转换JSON数组的对象,从两个属性值创建新的属性
- 在AngularJs中转换JSON对象
- 需要转换JSON格式
- 转换JSON中的字符串
- 如何转换json数组的JS
- jQuery UI自动完成与预转换json url
- 使用递归转换json数据
- 如何在jquery中转换json格式的数组
- 如何转换json没有& quot;