To start the mongo shell with other options, see examples of starting up mongo and mongo reference which provides details on the available options. 

Note: When starting, mongo checks the user’s HOME directory for a JavaScript file named .mongorc.js . If found, mongo interprets the content of .mongorc.js before displaying the prompt for the first time. If you use the shell to evaluate a JavaScript file or expression, either by using the --eval option on the command line or by specifying a .js file to mongo , mongo will read the .mongorc.js file after the JavaScript has finished processing. You can prevent .mongorc.js from being loaded by using the --norc option. 

## Executing Queries 

From the mongo shell, you can use the shell methods to run queries, as in the following example: 

db.<collection>.find() 

• The db refers to the current database. 

• The <collection> is the name of the collection to query. See Collection Help (page 277) to list the available collections. 

If the mongo shell does not accept the name of the collection, for instance if the name contains a space, hyphen, or starts with a number, you can use an alternate syntax to refer to the collection, as in the following: 

db["3test"].find() 

db.getCollection("3test").find() 

• The find() method is the JavaScript method to retrieve documents from <collection> . The find() method returns a cursor to the results; however, in the mongo shell, if the returned cursor is not assigned to a variable using the var keyword, then the cursor is automatically iterated up to 20 times to print up to the first 20 documents that match the query. The mongo shell will prompt Type it to iterate another 20 times. 

You can set the DBQuery.shellBatchSize attribute to change the number of iteration from the default value 20 , as in the following example which sets it to 10 : 

DBQuery.shellBatchSize = 10; 

For more information and examples on cursor handling in the mongo shell, see Cursors (page 64). 

See also Cursor Help (page 277) for list of cursor help in the mongo shell. 

For more documentation of basic MongoDB operations in the mongo shell, see: • Getting Started with MongoDB 108 

• mongo Shell Quick Reference (page 278) 

• Read Operations (page 60) 

• Write Operations (page 73) 

• Indexing Tutorials (page 517) 

## Print 

The mongo shell automatically prints the results of the find() method if the returned cursor is not assigned to a variable using the var keyword. To format the result, you can add the .pretty() to the operation, as in the 

