Aggregation Cursor Required


This question isn’t specifically related to any course related work but more to a bit of confusion I have come up against.

I was reading the documentation on aggregation and came to the examples section that has you import a zip codes collection and attempted this on my personal machine.
My setup is MongoDB server version: 4.0.5 and I have a 3 member replica set. I can successfully import the data without problem and can perform basic queries on the collection. The issues comes when I attempt to run the aggregate command it suggests in the documentation, here, and I receive the error message:

"The 'cursor' option is required, except for aggregate with the explain argument"

I actually brought up this issue while in the MongoDB Performance course and just kind of went with it after we couldn’t figure out why I was being required to use the cursor option. Now though, I am faced with this same issue, and thought someone in the aggregation course may be a bit more familiar with why this is happening. I can’t find anywhere in the documentation that states that this is required for version 4.0, and it appears there are two separate sections for commands, Database and shell methods. The course appears to be using the commands that align with the shell methods, and just reading the docs that seems to be correct as well. Based on the docs I am stumped as to why I keep getting this cursor required message when aggregating on my local 4.0.5 replica set. I even switched to the 4.2 version of the docs and it still shows the cursor option as optional in the shell command section.

Is there some way that I am being forced to submit Database commands instead of shell methods, perhaps? Anyway to change that? Any feedback would be appreciated because this is pretty confusing, for me.

Thank you,

SOLUTION(my fault):

I noticed, by comparing to my vagrant box, that my local mongo shell showed mongod 4.0.5, and the vagrant just showed MongoDB Enterprise when connected to the shell. This led me to believe that I was not loading the actual Mongo Shell on my local machine, somehow. In an attempt to fix my issue, I was going through the mongo shell command line options to try and see if I could pin down what could cause this. I got to the the --norc option and, bam! MongoDB Enterprise shows properly, tested the aggregate, and it works as expected.

I open the mongorc and find all the color options and functions and fun stuff that was put there by mongo-hacker. I had installed this quite a while ago for a course outside of MongoDB University and, just kept it because the formatting was nice. That led me to their github page where the issue was resolved in an update! I just went ahead and uninstalled it because the frustration was not worth the formatting.

Now I see why finding an answer for this was so challenging and, I apologize for any time lost on my issue.

Thanks again!

@ Christopher_79126

Glad you solved it. I’m the same TA who “helped”:roll_eyes: before and will make a note of this in case it comes up again. Thanks.

1 Like