我一直在通过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'}
}})
我希望将确切的语法发送到服务器,该服务器将同时返回“注释”和“问题”。