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
元素。我发现文档在这方面很有帮助