MongoDB Group using Ruby driver

前端 未结 1 1138
我寻月下人不归
我寻月下人不归 2021-01-13 15:19

I\'m trying to bring back a list of year/month combinations with counts for describing blog posts. The idea is that they will be displayed like so:

  • January 201
1条回答
  •  一生所求
    2021-01-13 15:58

    That's pretty strange behavior. I just ran your code locally, and everything worked. Can you verify that you're using the driver version 0.18.2? If so, make sure that that's the only version installed (just as a sanity check).

    I don't think it should make any difference, but I wasn't running #group from MongoMapper -- I was using the gem alone. You might try that, too. Here's the code I ran:

    require 'rubygems'
    require 'mongo'
    
    d = Mongo::Connection.new.db('blog')
    c = d['post']
    
    p c.group("function(x) { return { month: x.date.getMonth(), year:x.date.getFullYear() }; }", 
      nil, 
      { :count => 0 }, 
      "function(x,y){y.count++}", 
      true)
    

    0 讨论(0)
提交回复
热议问题