简体   繁体   English

MongoDB Compass 聚合 $match 过滤器返回 null

[英]MongoDB Compass aggregations $match filter returns null

I have collection in mongodb and its size is 5.7 million.我在 mongodb 中有集合,其大小为 570 万。 But I have problem with the $match filter.但是我对 $match 过滤器有问题。 I'm trying a query with this command:我正在尝试使用此命令进行查询

{ date:{ $gte: "2019-07-16", $lte: "2019-07-16" } }

returns 10k documents.返回 10k 个文档。

But I'm trying $match aggregations with the same command and it returns nothing.但是我正在尝试使用相同的命令进行$match 聚合,但它什么都不返回。

My sample document;我的样本文件;

{
"_id":"5c1a231f1923047866f3ffb0",
"no":"20",
"id":"007",
"Typee":"Real",
"type":"noInternet",
"dealersTitle":"John",
"yesterday_total":"65.52",
"mastercard_number":"0",
"mastercard_total":"0",
"mastercard_balance":"0",
"rfCard_number":"6",
"rfCart_total":"65",
"rfBalance_number":"0",
"rfBalance_total":"0",
"todayBalance":"0.52",
"balanceRfTotal":"0",
"date":"2019-07-16"
}

I don't understand where the problem comes from.我不明白问题出在哪里。

Edited: It returns result when I try aggregation on terminal.编辑:当我在终端上尝试聚合时它返回结果。 Why Mongo Compass doesn't see my collection in the aggregation tab.为什么 Mongo Compass 在聚合选项卡中看不到我的收藏。 (N/A Documents in the Collection) (不适用集合中的文件)

Sample document shows that your date attribute is saved as string and not date.示例文档显示您的日期属性保存为字符串而不是日期。

{ "_id":"5c1a231f1923047866f3ffb0", "no":"20", "id":"007", "Typee":"Real", "type":"noInternet", "dealersTitle":"John", "yesterday_total":"65.52", "mastercard_number":"0", "mastercard_total":"0", "mastercard_balance":"0", "rfCard_number":"6", "rfCart_total":"65", "rfBalance_number":"0", "rfBalance_total":"0", "todayBalance":"0.52", "balanceRfTotal":"0", "date":"2019-07-16" } { "_id":"5c1a231f1923047866f3ffb0", "no":"20", "id":"007", "Typee":"Real", "type":"noInternet", "dealersTitle":"John", "昨天_total":"65.52", "mastercard_number":"0", "mastercard_total":"0", "mastercard_balance":"0", "rfCard_number":"6", "rfCart_total":"65", "rfBalance_number" :"0", "rfBalance_total":"0", "todayBalance":"0.52", "balanceRfTotal":"0", "date":"2019-07-16" }

if you use data type as date you can easily compare dates.如果您使用数据类型作为日期,您可以轻松地比较日期。

"date": {"$date":"2019-07-16"} “日期”:{“$date”:“2019-07-16”}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM