Useful mongo commands

Useful mongo commands with authentication

  • Mongo connection with authentication   – mongo example.com:27017/testdb -u azeem  -p test123 –authenticationDatabase admin;
  • Eexporting a collection  –  mongoexport -h localhost -u azeem -p test123 -d testdb -c places –out places.json
  •  Importing a collection     –  mongoimport -h localhost -u azeem -p test123 -d backups -c places < places.json
  • Renaming a collection     –     db.places.renameCollection(‘place’);
  • Mongo dump    –              mongodump -h localhost -u test-p test123  -d dbtest -o dump
  • Mongo restore (please check whether u have created a user for the perticular DB instance with read and write permisssion) –sudo mongore store -h http://www.example.com –port 27017 -u username-p password –
    d dbname  dubmpname
  • New field to the collection – db.places.update({},$set”region “:”Asia”}},upsert:false,multi:true}
  • Mongo unrestricted user account:

    In the admin database, create a new user using the db.createUser() method. Give the user the built-in root role.

    For example:

    use admin
    db.createUser(
        {
          user: "superuser",
          pwd: "12345678",
          roles: [ "root" ]
        }
    )

 

Advertisements

One thought on “Useful mongo commands

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s