{"action":"created","issue":{"url":"https://api.github.com/repos/mongosoup/rmongodb/issues/82","labels_url":"https://api.github.com/repos/mongosoup/rmongodb/issues/82/labels{/name}","comments_url":"https://api.github.com/repos/mongosoup/rmongodb/issues/82/comments","events_url":"https://api.github.com/repos/mongosoup/rmongodb/issues/82/events","html_url":"https://github.com/mongosoup/rmongodb/issues/82","id":63904266,"number":82,"title":"rmongodb aggregate fails on group by time field","user":{"login":"nathanwebb","id":1356271,"avatar_url":"https://avatars.githubusercontent.com/u/1356271?v=3","gravatar_id":"","url":"https://api.github.com/users/nathanwebb","html_url":"https://github.com/nathanwebb","followers_url":"https://api.github.com/users/nathanwebb/followers","following_url":"https://api.github.com/users/nathanwebb/following{/other_user}","gists_url":"https://api.github.com/users/nathanwebb/gists{/gist_id}","starred_url":"https://api.github.com/users/nathanwebb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nathanwebb/subscriptions","organizations_url":"https://api.github.com/users/nathanwebb/orgs","repos_url":"https://api.github.com/users/nathanwebb/repos","events_url":"https://api.github.com/users/nathanwebb/events{/privacy}","received_events_url":"https://api.github.com/users/nathanwebb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-03-24T05:10:39Z","updated_at":"2015-03-29T19:51:38Z","closed_at":null,"body":"Hi,\r\n\r\nI have an aggregation pipeline grouping document that is working fine in the mongo shell, but not in rmongodb.\r\n\r\nA sample document (after running through match and unwind stages) is pretty simple, like this:\r\nThere is a time (t) and a value (v), and a time series identifier (ts)\r\n```\r\n    {\r\n      \"_id\": {\r\n        \"str\": \"55093a7ea99062278a877f9e\"\r\n      },\r\n      \"ts\": {\r\n        \"str\": \"55093a7ea99062278a877f9d\"\r\n      },\r\n      \"t\": \"2015-03-18T06:59:38.000Z\",\r\n      \"v\": 4928737\r\n    }\r\n```\r\n\r\nThe json for the group stage is just getting the average for each hour for each time series.\r\n```\r\n{\r\n  \"$group\":  {\r\n       \"_id\": {\r\n           \"ts\":\"$ts\",\r\n           \"hourofday\":{\"$hour\":\"$t\"}\r\n        },\r\n        \"v\":{\"$avg\":\"$v\"}\r\n     }\r\n }\r\n```\r\n\r\nWhen I try it with rmongodb, it fails with a error code 10.\r\n\r\nThis doesn't work:\r\n```\r\ngroup.bson = mongo.bson.from.JSON('{\"$group\":{\"_id\":{\"ts\":\"$ts\",\"hourofday\":{\"$hour\":\"$t\"}},\"v\":{\"$avg\":\"$v\"}}}')\r\n```\r\n\r\nBut if I remove the \"hourofday\" part of the id, then it works, apart from not being the right result:\r\n\r\nThis works:\r\n```\r\ngroup.bson = mongo.bson.from.JSON('{\"$group\":{\"_id\":{\"ts\":\"$ts\"}},\"v\":{\"$avg\":\"$v\"}}}')\r\n```\r\n\r\nI've tried constructing this with buffers, but that made no difference.  The BSON that is output looks correct to me is this:\r\n\r\n```\r\n\t$group : 3 \t \r\n\t\t_id : 3 \t \r\n\t\t\tts : 2 \t $ts\r\n\t\t\thourofday : 3 \t \r\n\t\t\t\t$hour : 2 \t $t\r\n\r\n\r\n\t\tv : 3 \t \r\n\t\t\t$avg : 2 \t $v\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/mongosoup/rmongodb/issues/comments/87462551","html_url":"https://github.com/mongosoup/rmongodb/issues/82#issuecomment-87462551","issue_url":"https://api.github.com/repos/mongosoup/rmongodb/issues/82","id":87462551,"user":{"login":"davidski","id":2313762,"avatar_url":"https://avatars.githubusercontent.com/u/2313762?v=3","gravatar_id":"","url":"https://api.github.com/users/davidski","html_url":"https://github.com/davidski","followers_url":"https://api.github.com/users/davidski/followers","following_url":"https://api.github.com/users/davidski/following{/other_user}","gists_url":"https://api.github.com/users/davidski/gists{/gist_id}","starred_url":"https://api.github.com/users/davidski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidski/subscriptions","organizations_url":"https://api.github.com/users/davidski/orgs","repos_url":"https://api.github.com/users/davidski/repos","events_url":"https://api.github.com/users/davidski/events{/privacy}","received_events_url":"https://api.github.com/users/davidski/received_events","type":"User","site_admin":false},"created_at":"2015-03-29T19:51:38Z","updated_at":"2015-03-29T19:51:38Z","body":"@nathanwebb, can you post the `unwind` query you have working under 1.8.0 of `rmongodb`? I'm just getting started with this package and every unwind I try fails. I also get the `group` related errors whenever I'm using something that references a field via quoting `\"$hour\"` for instance. I'm suspecting some sort of error related to fields that need to be quoted.\r\nEven using the example `zips` file fails (error code 10) when running the commands:\r\n```\r\npipe_test <- mongo.bson.from.JSON('{ \"$unwind\": \"$city\"}')\r\ncmd_list <- list(pipe_test)\r\nmongo.aggregation(m, \"rmongodb.zips\", cmd_list)\r\nres <- mongo.aggregation(m, ns, cmd_list)\r\nresult <- mongo.bson.value(res, \"result\")\r\n```"}}