在mongodb中使用$ and和$ match [英] using $and with $match in mongodb

查看:505
本文介绍了在mongodb中使用$ and和$ match的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在MongoDB中使用以下查询,但该查询未运行.

I am trying to use the following query in MongoDB but it is not running.

db.test.aggergate(
$match: {$and: [type: {$in: ["TOYS"]}, type: {$nin: ["BARBIE"]}, time: 
{$lt:ISODate("2013-12-09T00:00:00Z")}]}})

它说出无效字符:".

是否可以将$ and与$ match一起使用?我在该论坛上看到了一个$或$ match的示例,所以我认为这是可能的.

Is it possible to use $and with $match? I have seen an example on this forum of $or with $match so I presumed this is possible.

在此先感谢您的帮助和指导.

Thank you in advance for your help and guidance.

推荐答案

$和$ match可以正常工作.

$and with $match works just fine.

查询中存在语法错误.试试这个.

You have syntax errors in your query. Try this.

db.test.aggregate([
                   { 
                     $match: {
                          $and: [ 
                              {type: {$in: ["TOYS"]}}, 
                              {type: {$nin: ["BARBIE"]}}, 
                              {time: {$lt:ISODate("2013-12-09T00:00:00Z")}}
                          ]
                     }
                   }
                  ])

对于您想做的事情,您不需要$and.

And for what you are trying to do, you do not need an $and.

这篇关于在mongodb中使用$ and和$ match的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆