Chapter 5 limit() TypeError: cmdResult.cursor is undefined

For any statement where we sort() and limit():

For example: db.companies.find({“founded_year”: {$ne: null}},{“name”:1,“founded_year”:1}).sort({“founded_year”:1}).limit(5)

Here’s the behavior I’m seeing. (1)If I run the statement for the first time with the limit, I get "TypeError: cmdResult.cursor is undefined ". (2) Next, if I run it without the limit, I get ascending results. (3) Next, if I run it with the limit(), and get the same results to the limit set. (4) Then if I run the exact same statement including the limit() it says “TypeError: cmdResult.cursor is undefined” as if there were no results in the cursor anymore. Then (5) if I run it again without the limit, I get results as in (2).

It’s repeatable and doesn’t matter which collection I use.

What could be causing this behavior?

Thanks for any insight!

Please share a screenshot of what you are doing exactly. This is supposed to work so may be it is the context and the screenshot will provide us with it.

The session expired and when I opened a new session I could not reproduce the behavior. Perhaps there was something wrong with that session.

Hi @Peggy_Bishop, :wave:

We hope you were able to solve your above issue.
If not you can surely share all the different queries which you have tried.
We will be happy to help. Feel free to reach out for any other issues.

Good Luck with the rest of the course.


I am seeing the same issue.

Hi @Anmol_Kushwaha,

Can you kindly share all the different queries which you have tried?
We will be happy to help…!!