0

A beginner to mongoDB. went through this website to know how to create a javascript file . .mongorc.js and

<code>
function insertData(dbName, colName, num)
{
var col = db.getSiblingDB(dbName).getCollection(colName);
for (i = 0; i < num; i++) 
{
col.insert({x:i});
}
print(col.count());
}
<code>

and the link is here function insertData ... the tutorial adviced to store the function in a javascript file called .mongorc.js . I dont know how to create it and use it and where to store it . need help .

1 Answer 1

3

.mongorc.js

The .mongorc.js file is used if you want to have some JavaScript loaded every time you start the mongo shell:

  • On Linux, Unix, and OS X mongo looks for this file in $HOME/.mongorc.js.

  • On Windows, mongo.exe looks for this file in %HOME%.mongorc.js or %HOMEDRIVE%%HOMEPATH%.mongorc.js.

Typically you only want to store re-usable functions in your .mongorc.js.

Other ways to load JavaScript into a mongo shell session include:

  • using the load() command in a mongo shell: load("/path/to/something.js").

  • passing a JavaScript filename as a command line parameter when starting the mongo shell: mongo /path/to/something.js

  • pasting JavaScript directly into the mongo shell (e.g. copy & paste from a tutorial)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.