【问题标题】:MongoDB filtering issuesMongoDB过滤问题
【发布时间】:2021-10-09 08:54:57
【问题描述】:

我不确定我的代码有什么问题,我查看了文档,一切似乎都是正确的。我浏览了多个帖子并尝试了许多解决方案。

代码:

router.get('/rank/:rank', async (req, res) => {
    const users = await loadUserCollection()
    const query = users.find({rank: req.params.rank}, {projection: {email: 0, password: 0}})
    res.json(query)
})

async function loadUserCollection() {
    const client = await mongodb.MongoClient.connect(mongoUri, {useNewUrlParser: true})
    return client.db('myFirstDatabase').collection('users')
}

错误:

[0] (node:39544) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
[0]     --> starting at object with constructor 'ReplSet'
[0]     |     property 's' -> object with constructor 'Object'
[0]     |     property 'coreTopology' -> object with constructor 'ReplSet'
[0]     |     ...
[0]     |     property 's' -> object with constructor 'Object'
[0]     --- property 'topology' closes the circle
[0]     at JSON.stringify (<anonymous>)
[0]     at stringify (C:\______________\node_modules\express\lib\response.js:1123:12)
[0]     at ServerResponse.json (C:\_________\node_modules\express\lib\response.js:260:14)      
[0]     at C:\____________\routes\api\users.js:19:9
[0]     at processTicksAndRejections (internal/process/task_queues.js:95:5)

【问题讨论】:

    标签: node.js mongodb api vue.js express


    【解决方案1】:

    试试 const query = await users.find({rank: req.params.rank}, {projection: {email: 0, password: 0}})

    【讨论】:

      猜你喜欢
      • 2019-03-04
      • 2018-03-19
      • 1970-01-01
      • 2014-01-05
      • 2016-10-18
      • 2012-03-16
      • 2011-05-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多