javascript - TypeError: 将循环结构转换为 JSON\n
问题描述
我有一个端点,只返回一个模式的 countDocuments。我想返回一个这样的 JSON 对象
{count:3500}
但我收到了这个错误:
Converting circular structure to JSON\n --> starting at object with constructor 'NativeTopology'\n | property 's' -> object with constructor 'Object'\n | property 'sessionPool' -> object with constructor 'ServerSessionPool'\n --- property 'topology' closes the circle"}}
那是我的代码:
路由.js
router.get('/', asyncWrapper(async (req, res) => {
const census = await censusService.getCensus();
return res.send(census);
}));
人口普查服务.js
async function getCensus(){
return await censRepository.getCensus();
}
存储库.js
async getCensus(){
const { Cens: censSchema } = this.getSchemas();
const countCensus = censSchema.countDocuments({}, function(err, count) {
if (err) { return handleError(err) }
})
return {
count: countCensus
}
}
解决方案
推荐阅读
- javascript - 无法在 Javascript 中正确结束游戏
- android - 如何在我的科尔多瓦应用程序的 ionic 3 文本输入中限制特殊字符的输入?
- javascript - 在单击事件上更改元素节点列表的样式
- android-studio - 如何在 Android Studio 3.1.4 中正确添加 rhino - Android
- neo4j - 即使在 neo4j 中存在重复节点,也返回 1 个节点
- javascript - 如何在javascript中调用同一函数内部和外部的函数
- python - 在块中加载数据时 Pandas None 类型
- python - Python 加载 windows 库 C# 转换
- tornadofx - TornadoFX:标签未更新
- php - 单击聊天按钮时将用户移动到使用 AJAX 的聊天页面| 重要的