MongoDB Group using Ruby driver -


I am trying to bring back the list of year / month combinations with the calculation to describe the blog post

  • January 2010 (1 post)
  • December 2009 (2 posts)
  • ...
  • I have managed to use it in the Mongodi JS Shell, and it results in a useful format:

      db.posts.group ({Keyf: function (x) {return: month} x.datetime.g EtMonth (), year: x.datetime.getFullYear ()}}}, reduce: function (x, y) {y.count ++}, initial: {result:  
      [ {"Month": 0, "year": 2010, "count": 3}, {"month": 0, "year": 1970, "count": 1}]  

    It's very nice, okay what I'm doing after this. However, while trying to convert it to the appropriate code for the Ruby driver, I can not get it to work. Have seen, the same results in the following (I'm using Mongomper, therefore Post.collection ):

      @ collection = post.color.group ("function (x) {returns} {Month: x.datetime.getMonth (), year: x.datetime.getFullYear ()};} ", zero, {: calculation = & gt; Instead of returning the good array of useful data, I am getting this error: 0}, 'function (x, y) {y.count ++}', true)  

      {"function (x) {return {month: x.datetime.getMonth (), year: x.datetime.getFullYear ()};}" = & gt; Zero, "Count" = & gt; 4.0}  

    It seems that either it is completely rejecting your document (and my understanding of source code!) Or I'm missing out on some basics here . I'm almost pulling out my hair, gratefully accepted with any help.

    This is a very strange behavior. I just went to my code locally, and everything worked. Can you verify that you are using driver version 0.18.2? If so, make sure that this is the only version installed (just as a discretionary inquiry).

    I do not think it should make any difference, but I was not going to be the # group from MongoMapper. I was just using gem. You can also try that there is a code here that I ran Is:

      'rubygems' is required 'demand' d = Mongo :: connection. NY DB ('blog') C = D ['post'] PC group ("Work (X) {return {month: x.date.getMonth (), year: x.date.getFullYear ()}}}, zero , {: Calculation =>, "function (x, y) {y.count ++}", true)  

    Comments

    Popular posts from this blog

    oracle - The fastest way to check if some records in a database table? -

    php - multilevel menu with multilevel array -

    jQuery UI: Datepicker month format -