通过node.js将对象作为参数传递给mongodb

我一直在通过axios / express将字符串作为参数传递给我的mongodb,以用于数据库查询。 在前端,我传入参数“ Comment”或“ Question”:

 axios.get('http://localhost:4000/foo',{params: {
                type:
                    this.state.showComment === 'Comment' ? 'Comment' :
                    this.state.showComment === 'Question' ?  'Question'
            }})

在mongo查询的后端使用'type'参数:

*****.route('/foo').get(function (req,res) {
comments.aggregate([
    {$match: {contentType: req.query.type}} ...

我想添加一个'type'对象,该对象将返回同时'Comment'和'Question'与'$ match'相符的文档。

我尝试通过以下内容,但没有取得很大的成功:

axios.get('http://localhost:4000/foo',{params: {
                type:
                    this.state.showComment === 'Comment' ? 'Comment' :
                    this.state.showComment === 'Question' ?  'Question' :
                    {$or: 'Comment','Question'}
            }})

我希望将确切的语法发送到服务器,该服务器将同时返回“注释”和“问题”。

a5550846 回答:通过node.js将对象作为参数传递给mongodb

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3138964.html

大家都在问