MongoDB Execute script to initialize

Source: Internet
Author: User
Tags dba mongodb

Sometimes, when initializing the data, the number of command bars is too many, directly copy the INSERT statement, paste into the command line execution, very slow (time all spent on the paste above), so put the statement into the script to execute, more convenient. If, with the JS script, do not recognize the use database name, will be error: syntaxerror:unexpected identifier at a.js.

So, here's a 4.sh script, the script content:

Use DBA;
Db.a.insert ({"_id": 8});
Use DBA2;
Db.a.insert ({"_id": 8});

Execute script:

Mongo-u root-p 123456--authenticationdatabase admin--port 8000 < 4.sh > 4.log

>4.log refers to generating a log file.

4.log as follows:

MongoDB Shell version:2.6.9
Connecting To:127.0.0.1:8000/test
Switched to DB DBA
Writeresult ({"ninserted": 1})
Switched to DB DBA2
Writeresult ({"ninserted": 1})
Bye



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.