Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-1720

"mongo shell automatically prints results of find" misleading

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • Server_Docs_20231030
    • None
    • manual
    • None

    Description

      The following is misleading:

      The mongo shell automatically prints the results of the find() method if the returned cursor is not assigned to a variable.

      The above "trick" only works if the assignment is in an initializing statement (var c = db.collection.find()), but not simply if the "cursor is assigned to a variable" (c = db.collection.find()). The latter doesn't work because the assignment operator returns an expression, and if the given expression evaluates to a cursor object, the mongo shell calls next() on the cursor and prints the results.

      Attachments

        Activity

          People

            kay.kim@mongodb.com Kay Kim (Inactive)
            rassi J Rassi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              10 years, 26 weeks, 5 days ago