[SERVER-5874] "Group" functionality issued under 'cmd' gives different results than if issued from shell Created: 18/May/12 Updated: 15/Aug/12 Resolved: 21/May/12 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | 2.0.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Joe O | Assignee: | Chris Westin |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | commands | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Amazon Linux 64 bit running on EC2 |
||
| Operating System: | Linux |
| Participants: |
| Description |
|
I have a very very simple aggregation command I wrote and executed from the MongoDB shell, using the db.<collection>.group() interface. It worked flawlessly and I got the expected results. I then try to execute the same aggregation command via the 'cmd' format (in order to execute it over the Sleepy Mongoose interface via CURL) and it executed - only the aggregations all came back as '0'. Same data, same logic, etc. My reduce function in both cases: "$reduce":"function(obj,res) {res.count++}"}} When using the cmd interface, 'res' is initialized to 0, the resultset will have the count field for the group by category set to 0.0. I tried to use the floatApprox method, setting the initial value of count to 1.0, etc but to no avail. res.count never increments. Also, while troubleshooting this, I noticed several JSON parsing issues related to the '+' operator...it seemed as if Mongo wasn't treating res.count as a long or float. It works fine using the db.collection.group() interface. |
| Comments |
| Comment by Chris Westin [ 21/May/12 ] |
|
I've tried several variations in the shell, and they appear to work fine. So I think this is a problem with Sleepy.Mongoose, not the server. I an attempt to verify this, I tried installing and using Sleepy.Mongoose from https://github.com/kchodorow/sleepy.mongoose/tree/master/sleepymongoose . However, when I try to use it, I get errors from pymongo.son that it can't import SON. Our Python driver folks tell me this means that this package depends on a really old version of Pymongo. Then I also found out that we (10gen) don't officially support Sleepy.Mongoose. I would suggest pursuing this through the issue tracker associated with that project. |
| Comment by Joe O [ 18/May/12 ] |
|
Absolutely. This is the command that works from the shell: db.taxonomy_list.group({key: {"taxonomy":true},cond:{"coordinates" : {"$within" : {"$box" : [[-124.701058,24.434467], [-67.408986,49]]}}},initial: {count:0},reduce:function(doc,out){out.count++}}); This produces the following (expected) output: [ , , , , , etc...this works great! But when I try: curl --data 'cmd={"group" : {"ns": "taxonomy_list","key": {"taxonomy":1},"cond":{"coordinates" : {"$within" : {"$box" : [[-124.701058,24.434467], [-67.408986,49]]}}},"initial": {"count":0},"$reduce":"function(doc,out) {out.count++}"}}' http://localhost:27080/hhs/_cmd I get: {"count": 2384.0, "keys": 19, "retval": [ {"count": 0.0, "taxonomy": "Influenza"}, {"count": 0.0, "taxonomy": "Common Cold"}, {"count": 0.0, "taxonomy": "mosquito borne disease"}, {"count": 0.0, "taxonomy": "Tuberculosis"}, {"count": 0.0, "taxonomy": "Pertussis"}, {"count": 0.0, "taxonomy": "Gastroenteritis"}, {"count": 0.0, "taxonomy": "Sexually Transmitted Disease"}, {"count": 0.0, "taxonomy": "Yellow Fever"}, {"count": 0.0, "taxonomy": "Rabies"}, {"count": 0.0, "taxonomy": "Tetanus"}, {"count": 0.0, "taxonomy": "anthrax"}, {"count": 0.0, "taxonomy": "Meningitis"}, {"count": 0.0, "taxonomy": "Varicella"}, {"count": 0.0, "taxonomy": "Mumps"}, {"count": 0.0, "taxonomy": "Typhoid"}, {"count": 0.0, "taxonomy": "Pneumonia"}, {"count": 0.0, "taxonomy": "Malaria"}, {"count": 0.0, "taxonomy": "tick borne disease"}, {"count": 0.0, "taxonomy": "Polio"}], "ok": 1.0} NOTES: 1. Yes, it is a spatial query, but I get the same results when I change it to a simple filter, like {taxonomy:"Yellow Fever"}2. I've got a ssh tunnel set up between my local machine and Mongo on EC2. Never had any issues here. Lemme know if you need more, I could open the port on EC2 and let you in if it will help. This is all public data, nothing critical here. Lemme know, and thanks for the help! |
| Comment by Chris Westin [ 18/May/12 ] |
|
Could we please get the whole group command, along with a couple of sample data documents (suitably anonymized or obfuscated if necessary) ? Since you say the db.collection.group() (mongo shell) interface gives the correct result, there's likely something wrong with the mongoose access path, not the grouping code itself. So could you also please show us how you are invoking that, so that we can reproduce this and trace into it? |