Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在rails mongodb中查找特定月份的数据_Ruby On Rails_Mongodb_Mongoid_Aggregate - Fatal编程技术网

Ruby on rails 在rails mongodb中查找特定月份的数据

Ruby on rails 在rails mongodb中查找特定月份的数据,ruby-on-rails,mongodb,mongoid,aggregate,Ruby On Rails,Mongodb,Mongoid,Aggregate,我试图查询在特定月份创建的数据 @events = Event.aggregates([ { '$project': { _id: 1, created_at: 1,

我试图查询在特定月份创建的数据

@events = Event.aggregates([
                               {
                                   '$project': {
                                       _id: 1,
                                       created_at: 1,
                                       'month': {'$month': '$created_at'}
                                   },
                               },
                               {month: {'$match': 05}}
                           ])
总的来说没有给我任何结果

我收到了邮递员的回复

{
    "count": 0,
    "sum": null,
    "avg": null,
    "min": null,
    "max": null
}

就个人而言,我更喜欢
collection.aggregate
而不是
aggregates
。其次,
$match
管道是错误的。最后,即使它在ruby中工作,也不要编写
05
ans,有些语言可能会将其解释为八进制而不是十进制

@events = Event.collection.aggregate([
                               {
                                   '$project': {
                                       _id: 1,
                                       created_at: 1,
                                       'month': {'$month': '$created_at'}
                                   },
                               },
                               {"$match" => {"month" => {'$eq': 5}}}
                           ]).to_a

就个人而言,我更喜欢
collection.aggregate
而不是
aggregates
。其次,
$match
管道是错误的。最后,即使它在ruby中工作,也不要编写
05
ans,有些语言可能会将其解释为八进制而不是十进制

@events = Event.collection.aggregate([
                               {
                                   '$project': {
                                       _id: 1,
                                       created_at: 1,
                                       'month': {'$month': '$created_at'}
                                   },
                               },
                               {"$match" => {"month" => {'$eq': 5}}}
                           ]).to_a

我将如何在其中插入查询元素?就像我们在where case中插入的一样。更简单的
$match
元素。我发现文档在这方面非常有用,我将如何在其中插入查询元素?就像我们在where case中插入的一样。更简单的
$match
元素。我发现文档在这方面很有帮助