Common mongodb commands-automated O & M

Source: Internet
Author: User
Tags mongodb commands

Common mongodb commands-automated O & M
Common mongodb commands are scripted-automated O & M writes some mongodb commands commonly used in O & M into shell scripts, greatly facilitating maintenance
1. Set replica set
#! /Bin/bash
# Mongodb enters the client and uses admin
Cd/usr/mongodb/bin
MongoDB = './mongo 192.168.1.7: 37017'
$ MongoDB <EOF
Use admin
Rsconf = {
"_ Id": "Job001 ",
"Members ":[
{
"_ Id": 0,
"Host": "192.168.1.seven: 37017"
}
]
}
Rs. initiate (rsconf)
Rs. add ("192.168.1.8: 37017 ")
Rs. add ("192.168.1.9: 37017 ")
Exit;
EOF

Note: Write the above content to the chmod 777 ***. sh file to grant the permission

In linux> sh ***. sh, you can complete the commands.

Same below
2. Modify replica set settings

#! /Bin/bash

# Mongodb enters the client and enters the primary
Cd/usr/mongodb/bin
MongoDB = './mongo 192.168.1.7: 37017'
$ MongoDB <EOF
Use Role modeljobresume
# Rs. status ()
Cfg = rs. conf ()
Cfg. members [0]. priority = 99
Cfg. members [1]. priority = 50
Cfg. members [2]. priority = 30
Rs. reconfig (cfg)
Rs. conf ()
Exit;

EOF

3. convert a table to a temporary table and copy it back. In this way, the complete log is generated again in oplog (the size of oplog must be large enough)

#! /Bin/bash
# Mongodb enters the client and enters the primary
Cd/usr/mongodb/bin
MongoDB = './mongo 192.168.1.7: 37017'
$ MongoDB <EOF
Use Role modeljobresume
Rs. remove ("192.168.1.8: 37017 ")
Rs. remove ("192.168.1.9: 37017 ")
Db. tbJobResume. renameCollection ("tbJobResumeOld ")
Db. tbJobResumeOld. copyTo ("tbJobResume ")
Rs. add ("192.168.1.8: 37017 ")
Rs. add ("192.168.1.9: 37017 ")
# Db. tbJobResumeOld. drop ()
Exit;
EOF

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.