[DOCS-989] Information about scripting the JS shell is missing from the latest documentation. Created: 15/Jan/13  Updated: 24/Sep/13  Resolved: 17/Sep/13

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: William Zola Assignee: Sam Kleinman (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

http://docs.mongodb.org/manual/tutorial/write-scripts-for-the-mongo-shell/


Issue Links:
Depends
Participants:
Days since reply: 10 years, 22 weeks, 1 day ago

 Description   

Information from the old Wiki page is no longer available in the revised manual: see below for details



 Comments   
Comment by auto [ 17/Sep/13 ]

Author:

{u'username': u'tychoish', u'name': u'Sam Kleinman', u'email': u'samk@10gen.com'}

Message: DOCS-989 additional edits
Branch: master
https://github.com/mongodb/docs/commit/4933b1a75d574d0551d6e9dfb40fbca966801340

Comment by William Zola [ 17/Sep/13 ]

Some information is still missing from the docs: there's no mention of how the 'it' command is not available in scripts.

Comment by auto [ 05/Aug/13 ]

Author:

{u'username': u'tychoish', u'name': u'Sam Kleinman', u'email': u'samk@10gen.com'}

Message: DOCS-989: clarifying organization and adding a point about printing.
Branch: master
https://github.com/mongodb/docs/commit/2325d3fa10a45e7e3928d064520dd71c4ec478b9

Comment by Sam Kleinman (Inactive) [ 05/Aug/13 ]

more edits coming soon.

Comment by auto [ 05/Aug/13 ]

Author:

{u'username': u'tychoish', u'name': u'Sam Kleinman', u'email': u'samk@10gen.com'}

Message: DOCS-989: clarifying organization
Branch: master
https://github.com/mongodb/docs/commit/f09b87830679bd06e4811687f637de9f9acada11

Comment by William Zola [ 15/Jan/13 ]

Here are the old documentation comments that are not present in the new version:

Please be aware there are data format issues in javascript so you should be careful how much you do in Javascript.

Printing

When using the shell interactively, the shell will print returned values and format where possible. This is done as a general convenience from within the shell. However, when building a script, the printing needs to be defined explicitly.

There are two functions commonly used for this:

  • print(): works as normal javascript
  • printjson(): prints a nicely formatted JSON representation of the given object

use dbname

This command does not work in scripted mode. Instead you will need to explicitly define the database in the connection

it

The iterator command it does not work outside of the interactive scripting environment.

getLastError

When running an update/insert command from the shell, the shell automatically awaits a reply (i.e. runs a get last error).

The same is not true when running from a script file. To wait for the status of an operation (such as a write), run the getLastError function after update/insert.

Generated at Thu Feb 08 07:39:59 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.