Thursday, October 04, 2018

MongoDB Backup and Recovery


MONGODUMP


To back up whole mongoDB server backup



[mdashok@nosqlDB ~]$ mongodump -h localhost:27017

2018-09-30T17:45:22.873+0530    writing admin.system.users to
2018-09-30T17:45:22.874+0530    done dumping admin.system.users (1 document)
2018-09-30T17:45:22.874+0530    writing admin.system.version to
2018-09-30T17:45:22.875+0530    done dumping admin.system.version (2 documents)
2018-09-30T17:45:22.875+0530    writing ashokdb.users to
2018-09-30T17:45:22.875+0530    writing ashokdb.doccollect to
2018-09-30T17:45:22.875+0530    writing ashokdb.doccollect4 to
2018-09-30T17:45:22.876+0530    writing ashokdb.mycoll to
2018-09-30T17:45:22.878+0530    done dumping ashokdb.doccollect (4 documents)
2018-09-30T17:45:22.878+0530    done dumping ashokdb.users (40 documents)
2018-09-30T17:45:22.879+0530    done dumping ashokdb.mycoll (0 documents)
2018-09-30T17:45:22.881+0530    done dumping ashokdb.doccollect4 (0 documents)




[mdashok@nosqlDB ashokdb]$ ls -ltr
total 24
-rw-r--r--. 1 mdashok mongodb  127 Sep 30 17:45 users.metadata.json
-rw-r--r--. 1 mdashok mongodb  155 Sep 30 17:45 mycoll.metadata.json
-rw-r--r--. 1 mdashok mongodb  132 Sep 30 17:45 doccollect.metadata.json
-rw-r--r--. 1 mdashok mongodb  160 Sep 30 17:45 doccollect4.metadata.json
-rw-r--r--. 1 mdashok mongodb    0 Sep 30 17:45 doccollect4.bson
-rw-r--r--. 1 mdashok mongodb    0 Sep 30 17:45 mycoll.bson
-rw-r--r--. 1 mdashok mongodb 3622 Sep 30 17:45 users.bson
-rw-r--r--. 1 mdashok mongodb  699 Sep 30 17:45 doccollect.bson
[mdashok@nosqlDB ashokdb]$



#Backup a Whole Database


MongoDB Enterprise > use ashokdb
switched to db ashokdb
MongoDB Enterprise > db.stats().dataSize;
4321
MongoDB Enterprise >




[mdashok@nosqlDB ~]$ date
Sun Sep 30 17:49:58 IST 2018

[mdashok@nosqlDB ~]$ mongodump -d ashokdb -o mongodb_dump

2018-09-30T17:50:12.100+0530    writing ashokdb.users to
2018-09-30T17:50:12.118+0530    writing ashokdb.doccollect to
2018-09-30T17:50:12.118+0530    writing ashokdb.doccollect4 to
2018-09-30T17:50:12.118+0530    writing ashokdb.mycoll to
2018-09-30T17:50:12.120+0530    done dumping ashokdb.users (40 documents)
2018-09-30T17:50:12.120+0530    done dumping ashokdb.doccollect (4 documents)
2018-09-30T17:50:12.121+0530    done dumping ashokdb.mycoll (0 documents)
2018-09-30T17:50:12.121+0530    done dumping ashokdb.doccollect4 (0 documents)
[mdashok@nosqlDB ~]$



yis/mdashok/mongodb_dump
[mdashok@nosqlDB mongodb_dump]$ ll
total 4
drwxr-xr-x. 2 mdashok mongodb 4096 Sep 30 17:50 ashokdb


[mdashok@nosqlDB mongodb_dump]$

# Backup a Single Collection


Backup collections from database

[mdashok@nosqlDB ~]$ mongodump -d ashokdb -o mongodbBackup --collection mycoll

2018-09-30T18:05:39.365+0530    writing ashokdb.mycoll to
2018-09-30T18:05:39.365+0530    done dumping ashokdb.mycoll (0 documents)

[mdashok@nosqlDB ~]$ mongodump -d ashokdb -o mongodbBackup --collection users

2018-09-30T18:05:50.688+0530    writing ashokdb.users to
2018-09-30T18:05:50.689+0530    done dumping ashokdb.users (40 documents)
[mdashok@nosqlDB ~]$

/yis/mdashok/mongodbBackup/ashokdb
[mdashok@nosqlDB ashokdb]$ ls -ltr
total 12
-rw-r--r--. 1 mdashok mongodb  155 Sep 30 18:05 mycoll.metadata.json
-rw-r--r--. 1 mdashok mongodb    0 Sep 30 18:05 mycoll.bson
-rw-r--r--. 1 mdashok mongodb  127 Sep 30 18:05 users.metadata.json
-rw-r--r--. 1 mdashok mongodb 3622 Sep 30 18:05 users.bson
[mdashok@nosqlDB ashokdb]$


# Take a backup of database with -excludeCollection

[mdashok@nosqlDB ~]$ mongodump -d ashokdb -o mongodbBackup --excludeCollection=doccollect4

2018-09-30T19:17:48.898+0530    writing ashokdb.users to
2018-09-30T19:17:48.898+0530    writing ashokdb.doccollect to
2018-09-30T19:17:48.898+0530    writing ashokdb.mycoll to
2018-09-30T19:17:48.900+0530    done dumping ashokdb.users (40 documents)
2018-09-30T19:17:48.901+0530    done dumping ashokdb.doccollect (4 documents)
2018-09-30T19:17:48.901+0530    done dumping ashokdb.mycoll (0 documents)

[mdashok@nosqlDB ~]$ cd mongodbBackup/ashokdb
[mdashok@nosqlDB ashokdb]$ ls -ltr
total 20
-rw-r--r--. 1 mdashok mongodb  127 Sep 30 19:17 users.metadata.json
-rw-r--r--. 1 mdashok mongodb  155 Sep 30 19:17 mycoll.metadata.json
-rw-r--r--. 1 mdashok mongodb    0 Sep 30 19:17 mycoll.bson
-rw-r--r--. 1 mdashok mongodb  132 Sep 30 19:17 doccollect.metadata.json
-rw-r--r--. 1 mdashok mongodb 3622 Sep 30 19:17 users.bson
-rw-r--r--. 1 mdashok mongodb  699 Sep 30 19:17 doccollect.bson
[mdashok@nosqlDB ashokdb]$

# Take a collection backup with excludeCollectionWithPrefix option:

[mdashok@nosqlDB ~]$ mongodump -d ashokdb -o mongodbBackup --excludeCollectionsWithPrefix=d

2018-09-30T19:20:49.703+0530    writing ashokdb.users to
2018-09-30T19:20:49.704+0530    writing ashokdb.mycoll to
2018-09-30T19:20:49.706+0530    done dumping ashokdb.users (40 documents)
2018-09-30T19:20:49.707+0530    done dumping ashokdb.mycoll (0 documents)

We excluded the collection, which name starts with "d" prefix

[mdashok@nosqlDB mongodbBackup]$ cd ashokdb
[mdashok@nosqlDB ashokdb]$ ls -ltr
total 12
-rw-r--r--. 1 mdashok mongodb  127 Sep 30 19:20 users.metadata.json
-rw-r--r--. 1 mdashok mongodb  155 Sep 30 19:20 mycoll.metadata.json
-rw-r--r--. 1 mdashok mongodb    0 Sep 30 19:20 mycoll.bson
-rw-r--r--. 1 mdashok mongodb 3622 Sep 30 19:20 users.bson
[mdashok@nosqlDB ashokdb]$

#To check database version before starting mongodb 


[mdashok@nosqlDB mongodbBackup]$ mongodump -d ashokdb -o mongodbBackup --version

mongodump version: r4.0.0
git version: 3b07af3d4f471ae89e8186d33bbb1d5259597d51
Go version: go1.8.5
   os: linux
   arch: amd64
   compiler: gc
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
[mdashok@nosqlDB mongodbBackup]$


#Take a Backup of whole server from Primary of  Replication servers

$mongodump -h localhost:6666 -o /usr/repl_server_bkpdump/ 
-vvvv

















#server backup location









#Restore a collection from primary node:

Restore a collection Failover_test_doc from FOver_Test backup directory from primary server (port : 6666)

$mongorestore -h localhost:6666 -d FOver_Test repl_server_bkpdump/FOver_Test/Failover_test_doc.bson -c Failover_test_doc -vvvv








Backup a database using specific user who is having access to take a backup.


[mdashok@MongoDB ~]$ mongodump --db ashokdb -u "reportsUser" -p "user123" --out ReportsUserbkp

2018-10-04T17:51:45.193+0530    writing ashokdb.users to
2018-10-04T17:51:45.194+0530    writing ashokdb.doccollect to
2018-10-04T17:51:45.195+0530    writing ashokdb.Today to
2018-10-04T17:51:45.195+0530    writing ashokdb.doccollect4 to
2018-10-04T17:51:45.310+0530    done dumping ashokdb.users (40 documents)
2018-10-04T17:51:45.310+0530    writing ashokdb.mycoll to
2018-10-04T17:51:45.332+0530    done dumping ashokdb.doccollect (5 documents)
2018-10-04T17:51:45.332+0530    writing ashokdb.indx-doc1 to
2018-10-04T17:51:45.364+0530    done dumping ashokdb.Today (1 document)
2018-10-04T17:51:45.399+0530    done dumping ashokdb.doccollect4 (0 documents)
2018-10-04T17:51:45.417+0530    done dumping ashokdb.mycoll (0 documents)
2018-10-04T17:51:45.420+0530    done dumping ashokdb.indx-doc1 (0 documents)


[mdashok@MongoDB ~]$

#Backup Users and Roles:

mdashok@MongoDB ~]$ mongodump --db ashokdb -h localhost:27017 -u "reportsUser" -p "user123" --out Backuproles --dumpDbUsersAndRoles -vvvvv

2018-10-04T17:57:14.169+0530    will listen for SIGTERM, SIGINT, and SIGKILL
2018-10-04T17:57:14.339+0530    using auth schema version 5
2018-10-04T17:57:14.424+0530    enqueued collection 'ashokdb.doccollect4'
2018-10-04T17:57:14.456+0530    enqueued collection 'ashokdb.mycoll'
2018-10-04T17:57:14.493+0530    enqueued collection 'ashokdb.indx-doc1'
2018-10-04T17:57:14.533+0530    enqueued collection 'ashokdb.users'
2018-10-04T17:57:14.573+0530    enqueued collection 'ashokdb.doccollect'
2018-10-04T17:57:14.616+0530    enqueued collection 'ashokdb.Today'
2018-10-04T17:57:14.616+0530    enqueued collection 'ashokdb.$admin.system.users'
2018-10-04T17:57:14.616+0530    enqueued collection 'ashokdb.$admin.system.roles'
2018-10-04T17:57:14.616+0530    enqueued collection 'ashokdb.$admin.system.version'
2018-10-04T17:57:14.616+0530    dump phase I: metadata, indexes, users, roles, version
2018-10-04T17:57:14.616+0530            reading indexes for `ashokdb.indx-doc1`
2018-10-04T17:57:14.659+0530            reading indexes for `ashokdb.users`
2018-10-04T17:57:14.704+0530            reading indexes for `ashokdb.doccollect`
2018-10-04T17:57:14.737+0530            reading indexes for `ashokdb.Today`
2018-10-04T17:57:14.778+0530            reading indexes for `ashokdb.doccollect4`
2018-10-04T17:57:14.814+0530            reading indexes for `ashokdb.mycoll`
2018-10-04T17:57:14.851+0530    dumping users and roles for ashokdb
2018-10-04T17:57:14.890+0530    counted 1 document in ashokdb.$admin.system.users
2018-10-04T17:57:14.891+0530    counted 0 documents in ashokdb.$admin.system.roles
2018-10-04T17:57:14.892+0530    counted 2 documents in ashokdb.$admin.system.version
2018-10-04T17:57:14.892+0530    dump phase II: regular collections
2018-10-04T17:57:14.892+0530    finalizing intent manager with longest task first prioritizer
2018-10-04T17:57:14.892+0530    dumping up to 4 collections in parallel
2018-10-04T17:57:14.892+0530    starting dump routine with id=3
2018-10-04T17:57:14.893+0530    writing ashokdb.users to
2018-10-04T17:57:14.893+0530    starting dump routine with id=0
2018-10-04T17:57:14.893+0530    writing ashokdb.doccollect to
2018-10-04T17:57:14.894+0530    starting dump routine with id=1
2018-10-04T17:57:14.894+0530    writing ashokdb.Today to
2018-10-04T17:57:14.895+0530    starting dump routine with id=2
2018-10-04T17:57:14.895+0530    writing ashokdb.doccollect4 to
2018-10-04T17:57:14.956+0530    counted 5 documents in ashokdb.doccollect
2018-10-04T17:57:14.970+0530    done dumping ashokdb.doccollect (5 documents)
2018-10-04T17:57:14.970+0530    writing ashokdb.mycoll to
2018-10-04T17:57:14.977+0530    counted 40 documents in ashokdb.users
2018-10-04T17:57:14.977+0530    done dumping ashokdb.users (40 documents)
2018-10-04T17:57:14.977+0530    writing ashokdb.indx-doc1 to
2018-10-04T17:57:15.038+0530    counted 0 documents in ashokdb.doccollect4
2018-10-04T17:57:15.086+0530    counted 0 documents in ashokdb.mycoll
2018-10-04T17:57:15.087+0530    done dumping ashokdb.doccollect4 (0 documents)
2018-10-04T17:57:15.087+0530    ending dump routine with id=2, no more work to do
2018-10-04T17:57:15.103+0530    counted 0 documents in ashokdb.indx-doc1
2018-10-04T17:57:15.116+0530    done dumping ashokdb.mycoll (0 documents)
2018-10-04T17:57:15.116+0530    ending dump routine with id=0, no more work to do
2018-10-04T17:57:15.116+0530    done dumping ashokdb.indx-doc1 (0 documents)
2018-10-04T17:57:15.116+0530    ending dump routine with id=3, no more work to do
2018-10-04T17:57:15.117+0530    counted 1 document in ashokdb.Today
2018-10-04T17:57:15.117+0530    done dumping ashokdb.Today (1 document)
2018-10-04T17:57:15.117+0530    ending dump routine with id=1, no more work to do
2018-10-04T17:57:15.117+0530    dump phase III: the oplog
2018-10-04T17:57:15.117+0530    finishing dump
[mdashok@MongoDB ~]$

 

#Backup a collection by Filtering Data

[mdashok@MongoDB ~]$ mongodump --db ashokdb -h localhost:27017 --out Backup_filter_data_dump --collection doccollect --query '{by:"ashok"}' -vvvv

2018-10-04T17:21:27.790+0530    will listen for SIGTERM, SIGINT, and SIGKILL
2018-10-04T17:21:27.792+0530    enqueued collection 'ashokdb.doccollect'
2018-10-04T17:21:27.792+0530    dump phase I: metadata, indexes, users, roles, version
2018-10-04T17:21:27.792+0530            reading indexes for `ashokdb.doccollect`
2018-10-04T17:21:27.793+0530    dump phase II: regular collections
2018-10-04T17:21:27.793+0530    finalizing intent manager with legacy prioritizer
2018-10-04T17:21:27.793+0530    dumping up to 1 collections in parallel
2018-10-04T17:21:27.793+0530    starting dump routine with id=0
2018-10-04T17:21:27.793+0530    writing ashokdb.doccollect to
2018-10-04T17:21:27.793+0530    not counting query on ashokdb.doccollect
2018-10-04T17:21:27.794+0530    done dumping ashokdb.doccollect (2 documents)
2018-10-04T17:21:27.794+0530    ending dump routine with id=0, no more work to do
2018-10-04T17:21:27.794+0530    dump phase III: the oplog
2018-10-04T17:21:27.794+0530    finishing dump
[mdashok@MongoDB ~]$



MONGORESTORE

Restore Section


Restore Whole Database



First drop a database name : ashokdb

MongoDB Enterprise > show dbs
admin    0.000GB
ashokdb  0.000GB
config   0.000GB
local    0.000GB
MongoDB Enterprise > use ashokdb
switched to db ashokdb
MongoDB Enterprise > db
ashokdb
MongoDB Enterprise > db.dropDatabase()
{ "dropped" : "ashokdb", "ok" : 1 }
MongoDB Enterprise > show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
MongoDB Enterprise >


Now restore ashokdb database from backup

[mdashok@nosqlDB mongodb_dump]$ pwd
/yis/mdashok/mongodb_dump
[mdashok@nosqlDB mongodb_dump]$ ll
total 4
drwxr-xr-x. 2 mdashok mongodb 4096 Sep 30 17:50 ashokdb
[mdashok@nosqlDB mongodb_dump]$

[mdashok@nosqlDB ashokdb]$ pwd
/yis/mdashok/mongodb_dump/ashokdb
[mdashok@nosqlDB ashokdb]$ cd ..

backup location :-

[mdashok@nosqlDB mongodb_dump]$ pwd
/yis/mdashok/mongodb_dump
[mdashok@nosqlDB mongodb_dump]$ ll
total 4
drwxr-xr-x. 2 mdashok mongodb 4096 Sep 30 17:50 ashokdb

[mdashok@nosqlDB mongodb_dump]$ mongorestore -d ashokdb /yis/mdashok/mongodb_dump/ashokdb

2018-09-30T18:10:13.892+0530    the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead
2018-09-30T18:10:13.892+0530    building a list of collections to restore from /yis/mdashok/mongodb_dump/ashokdb dir
2018-09-30T18:10:13.893+0530    reading metadata for ashokdb.users from /yis/mdashok/mongodb_dump/ashokdb/users.metadata.json
2018-09-30T18:10:13.943+0530    reading metadata for ashokdb.doccollect from /yis/mdashok/mongodb_dump/ashokdb/doccollect.metadata.json
2018-09-30T18:10:13.944+0530    reading metadata for ashokdb.doccollect4 from /yis/mdashok/mongodb_dump/ashokdb/doccollect4.metadata.json
2018-09-30T18:10:13.944+0530    reading metadata for ashokdb.mycoll from /yis/mdashok/mongodb_dump/ashokdb/mycoll.metadata.json
2018-09-30T18:10:13.945+0530    restoring ashokdb.users from /yis/mdashok/mongodb_dump/ashokdb/users.bson
2018-09-30T18:10:13.989+0530    restoring ashokdb.doccollect from /yis/mdashok/mongodb_dump/ashokdb/doccollect.bson
2018-09-30T18:10:14.025+0530    restoring ashokdb.doccollect4 from /yis/mdashok/mongodb_dump/ashokdb/doccollect4.bson
2018-09-30T18:10:14.027+0530    no indexes to restore
2018-09-30T18:10:14.027+0530    finished restoring ashokdb.doccollect4 (0 documents)
2018-09-30T18:10:14.061+0530    no indexes to restore
2018-09-30T18:10:14.061+0530    finished restoring ashokdb.doccollect (4 documents)
2018-09-30T18:10:14.081+0530    no indexes to restore
2018-09-30T18:10:14.081+0530    finished restoring ashokdb.users (40 documents)
2018-09-30T18:10:14.081+0530    restoring ashokdb.mycoll from /yis/mdashok/mongodb_dump/ashokdb/mycoll.bson
2018-09-30T18:10:14.082+0530    no indexes to restore
2018-09-30T18:10:14.082+0530    finished restoring ashokdb.mycoll (0 documents)
2018-09-30T18:10:14.082+0530    done
[mdashok@nosqlDB mongodb_dump]$

now check the db:

MongoDB Enterprise > show dbs
admin   0.000GB
config  0.000GB
local   0.000GB
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise > show dbs
admin    0.000GB
ashokdb  0.000GB
config   0.000GB
local    0.000GB
MongoDB Enterprise > use ashokdb
switched to db ashokdb
MongoDB Enterprise > show collections
doccollect
doccollect4
mycoll
users
MongoDB Enterprise >


Restore Single Collection



MongoDB Enterprise > show collections
doccollect
doccollect4
mycoll
users

drop docollect4

MongoDB Enterprise > db.doccollect4.drop()
true

MongoDB Enterprise > show collections
doccollect
mycoll
users
MongoDB Enterprise >

Backup location#

[mdashok@nosqlDB ashokdb]$ pwd
/yis/mdashok/mongodb_dump/ashokdb
[mdashok@nosqlDB ashokdb]$ ls -ltr doccollect*
-rw-r--r--. 1 mdashok mongodb 132 Sep 30 17:50 doccollect.metadata.json
-rw-r--r--. 1 mdashok mongodb 160 Sep 30 17:50 doccollect4.metadata.json
-rw-r--r--. 1 mdashok mongodb   0 Sep 30 17:50 doccollect4.bson
-rw-r--r--. 1 mdashok mongodb 699 Sep 30 17:50 doccollect.bson
[mdashok@nosqlDB ashokdb]$


Now restore collection from backup

[mdashok@nosqlDB ashokdb]$ mongorestore -d ashokdb -c doccollect4 /yis/mdashok/mongodb_dump/ashokdb/doccollect4.bson

2018-09-30T18:17:41.276+0530    checking for collection data in /yis/mdashok/mongodb_dump/ashokdb/doccollect4.bson
2018-09-30T18:17:41.276+0530    reading metadata for ashokdb.doccollect4 from /yis/mdashok/mongodb_dump/ashokdb/doccollect4.metadata.json
2018-09-30T18:17:41.322+0530    restoring ashokdb.doccollect4 from /yis/mdashok/mongodb_dump/ashokdb/doccollect4.bson
2018-09-30T18:17:41.384+0530    no indexes to restore
2018-09-30T18:17:41.384+0530    finished restoring ashokdb.doccollect4 (0 documents)
2018-09-30T18:17:41.384+0530    done
[mdashok@nosqlDB ashokdb]$

Now check the collection stats from db:

MongoDB Enterprise > db
ashokdb
MongoDB Enterprise > show collections
doccollect
doccollect4
mycoll
users


# restore a collection to new database from backup .

$mongorestore --db docdb -h localhost:27017 --dir /yis/mdashok/mongodb_whole_server_bkp/ashokdb/doccollect --collection doccollect








#Backup and restore using specific user "reportsUser"

Take a full database backup of ashokdb(db name) using reportsUser 


[mdashok@MongoDB ~]$ mongodump --db ashokdb -u "reportsUser" -p "user123" -- full_db_ashokdb_user_reportsUser
2018-10-13T18:36:13.180+0530    positional arguments not allowed: [-- full_db_ashokdb_user_reportsUser]
2018-10-13T18:36:13.180+0530    try 'mongodump --help' for more information
[mdashok@MongoDB ~]$ mongodump --db ashokdb -u "reportsUser" -p "user123" --out full_db_ashokdb_user_reportsUser
2018-10-13T18:36:26.263+0530    writing ashokdb.users to
2018-10-13T18:36:26.294+0530    writing ashokdb.doccollect to
2018-10-13T18:36:26.295+0530    writing ashokdb.Today to
2018-10-13T18:36:26.295+0530    writing ashokdb.doccollect4 to
2018-10-13T18:36:26.360+0530    done dumping ashokdb.users (40 documents)
2018-10-13T18:36:26.360+0530    writing ashokdb.mycoll to
2018-10-13T18:36:26.423+0530    done dumping ashokdb.doccollect (5 documents)
2018-10-13T18:36:26.423+0530    writing ashokdb.indx-doc1 to
2018-10-13T18:36:26.464+0530    done dumping ashokdb.doccollect4 (0 documents)
2018-10-13T18:36:26.476+0530    done dumping ashokdb.Today (1 document)
2018-10-13T18:36:26.476+0530    done dumping ashokdb.mycoll (0 documents)
2018-10-13T18:36:26.502+0530    done dumping ashokdb.indx-doc1 (0 documents)


Restore fulldb backup with new name "newdb1" by using user= reportsUser

[mdashok@MongoDB ~]$ mongorestore --db newdb1 -u "reportsUser" -p "user123" --authenticationDatabase ashokdb --dir  /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb

2018-10-13T18:46:27.480+0530    the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead
2018-10-13T18:46:27.480+0530    building a list of collections to restore from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb dir
2018-10-13T18:46:27.520+0530    reading metadata for newdb1.users from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/users.metadata.json
2018-10-13T18:46:27.615+0530    restoring newdb1.users from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/users.bson
2018-10-13T18:46:27.616+0530    reading metadata for newdb1.doccollect from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/doccollect.metadata.json
2018-10-13T18:46:27.616+0530    reading metadata for newdb1.Today from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/Today.metadata.json
2018-10-13T18:46:27.617+0530    reading metadata for newdb1.doccollect4 from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/doccollect4.metadata.json
2018-10-13T18:46:27.760+0530    restoring newdb1.doccollect from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/doccollect.bson
2018-10-13T18:46:27.779+0530    no indexes to restore
2018-10-13T18:46:27.779+0530    finished restoring newdb1.users (40 documents)
2018-10-13T18:46:27.779+0530    reading metadata for newdb1.indx-doc1 from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/indx-doc1.metadata.json
2018-10-13T18:46:27.779+0530    restoring newdb1.Today from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/Today.bson
2018-10-13T18:46:27.839+0530    no indexes to restore
2018-10-13T18:46:27.839+0530    finished restoring newdb1.doccollect (5 documents)
2018-10-13T18:46:27.839+0530    reading metadata for newdb1.mycoll from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/mycoll.metadata.json
2018-10-13T18:46:27.854+0530    restoring newdb1.doccollect4 from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/doccollect4.bson
2018-10-13T18:46:27.875+0530    no indexes to restore
2018-10-13T18:46:27.875+0530    finished restoring newdb1.doccollect4 (0 documents)
2018-10-13T18:46:27.896+0530    no indexes to restore
2018-10-13T18:46:27.896+0530    finished restoring newdb1.Today (1 document)
2018-10-13T18:46:27.942+0530    restoring newdb1.indx-doc1 from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/indx-doc1.bson
2018-10-13T18:46:27.974+0530    no indexes to restore
2018-10-13T18:46:27.974+0530    finished restoring newdb1.indx-doc1 (0 documents)
2018-10-13T18:46:28.010+0530    restoring newdb1.mycoll from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/mycoll.bson
2018-10-13T18:46:28.013+0530    no indexes to restore
2018-10-13T18:46:28.013+0530    finished restoring newdb1.mycoll (0 documents)
2018-10-13T18:46:28.013+0530    done
[mdashok@MongoDB ~]$



Restore a collection without index for faster reloading the collection and we can rebuild the index later#


[mdashok@MongoDB ashokdb]$ mongorestore --db docdb --collection doccollect --dir doccollect.bson --noIndexRestore -vvvvv

2018-10-13T19:02:58.839+0530    using --dir flag instead of arguments
2018-10-13T19:02:58.839+0530    checking options
2018-10-13T19:02:58.839+0530            dumping with object check disabled
2018-10-13T19:02:58.840+0530    will listen for SIGTERM, SIGINT, and SIGKILL
2018-10-13T19:02:58.843+0530    connected to node type: standalone
2018-10-13T19:02:58.843+0530    standalone server: setting write concern w to 1
2018-10-13T19:02:58.843+0530    using write concern: w='1', j=false, fsync=false, wtimeout=0
2018-10-13T19:02:58.843+0530    mongorestore target is a file, not a directory
2018-10-13T19:02:58.843+0530    setting number of insertions workers to number of parallel collections (4)
2018-10-13T19:02:58.843+0530    checking for collection data in doccollect.bson
2018-10-13T19:02:58.843+0530    reading collection doccollect for database docdb from doccollect.bson
2018-10-13T19:02:58.843+0530    scanning directory doccollect.bson for metadata
2018-10-13T19:02:58.843+0530    found metadata for collection at doccollect.metadata.json
2018-10-13T19:02:58.843+0530    enqueued collection 'docdb.doccollect'
2018-10-13T19:02:58.843+0530    finalizing intent manager with multi-database longest task first prioritizer
2018-10-13T19:02:58.843+0530    restoring up to 4 collections in parallel
2018-10-13T19:02:58.843+0530    starting restore routine with id=3
2018-10-13T19:02:58.872+0530    starting restore routine with id=0
2018-10-13T19:02:58.872+0530    ending restore routine with id=0, no more work to do
2018-10-13T19:02:58.872+0530    starting restore routine with id=1
2018-10-13T19:02:58.872+0530    ending restore routine with id=1, no more work to do
2018-10-13T19:02:58.872+0530    starting restore routine with id=2
2018-10-13T19:02:58.872+0530    ending restore routine with id=2, no more work to do
2018-10-13T19:02:58.872+0530    reading metadata for docdb.doccollect from doccollect.metadata.json
2018-10-13T19:02:58.873+0530    collection docdb.doccollect already exists - skipping collection create
2018-10-13T19:02:58.873+0530    restoring docdb.doccollect from doccollect.bson
2018-10-13T19:02:58.875+0530    using 4 insertion workers
2018-10-13T19:02:58.907+0530    error: multiple errors in bulk operation:
  - E11000 duplicate key error collection: docdb.doccollect index: _id_ dup key: { : ObjectId('5bb0bd9aaf35aafba1581136') }
  - E11000 duplicate key error collection: docdb.doccollect index: _id_ dup key: { : ObjectId('5bb0bd9eaf35aafba1581137') }
  - E11000 duplicate key error collection: docdb.doccollect index: _id_ dup key: { : ObjectId('5bb0bda4af35aafba1581138') }
  - E11000 duplicate key error collection: docdb.doccollect index: _id_ dup key: { : ObjectId('5bb0bda7af35aafba1581139') }

2018-10-13T19:02:58.938+0530    no indexes to restore
2018-10-13T19:02:58.938+0530    finished restoring docdb.doccollect (5 documents)
2018-10-13T19:02:58.939+0530    ending restore routine with id=3, no more work to do
2018-10-13T19:02:58.939+0530    done

[mdashok@MongoDB ashokdb]$


#Using Parallel processes option for restore the database

[mdashok@MongoDB ashokdb]$ mongorestore --db docdb1013 --dir /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb -vvvvv --numParallelCollections 2


2018-10-13T19:06:40.433+0530    using --dir flag instead of arguments
2018-10-13T19:06:40.433+0530    checking options
2018-10-13T19:06:40.433+0530            dumping with object check disabled
2018-10-13T19:06:40.433+0530    will listen for SIGTERM, SIGINT, and SIGKILL
2018-10-13T19:06:40.434+0530    connected to node type: standalone
2018-10-13T19:06:40.434+0530    standalone server: setting write concern w to 1
2018-10-13T19:06:40.434+0530    using write concern: w='1', j=false, fsync=false, wtimeout=0
2018-10-13T19:06:40.434+0530    the --db and --collection args should only be used when restoring from a BSON file. Other uses are deprecated and will not exist in the future; use --nsInclude instead
2018-10-13T19:06:40.434+0530    mongorestore target is a directory, not a file
2018-10-13T19:06:40.434+0530    building a list of collections to restore from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb dir
2018-10-13T19:06:40.434+0530    reading collections for database docdb1013 in ashokdb
2018-10-13T19:06:40.435+0530    found collection docdb1013.Today bson to restore to docdb1013.Today
2018-10-13T19:06:40.435+0530    found collection metadata from docdb1013.Today to restore to docdb1013.Today
2018-10-13T19:06:40.435+0530    found collection docdb1013.doccollect bson to restore to docdb1013.doccollect
2018-10-13T19:06:40.435+0530    found collection metadata from docdb1013.doccollect to restore to docdb1013.doccollect
2018-10-13T19:06:40.435+0530    found collection docdb1013.doccollect4 bson to restore to docdb1013.doccollect4
2018-10-13T19:06:40.435+0530    found collection metadata from docdb1013.doccollect4 to restore to docdb1013.doccollect4
2018-10-13T19:06:40.435+0530    found collection docdb1013.indx-doc1 bson to restore to docdb1013.indx-doc1
2018-10-13T19:06:40.435+0530    found collection metadata from docdb1013.indx-doc1 to restore to docdb1013.indx-doc1
2018-10-13T19:06:40.435+0530    found collection docdb1013.mycoll bson to restore to docdb1013.mycoll
2018-10-13T19:06:40.435+0530    found collection metadata from docdb1013.mycoll to restore to docdb1013.mycoll
2018-10-13T19:06:40.435+0530    found collection docdb1013.users bson to restore to docdb1013.users
2018-10-13T19:06:40.435+0530    found collection metadata from docdb1013.users to restore to docdb1013.users
2018-10-13T19:06:40.435+0530    finalizing intent manager with multi-database longest task first prioritizer
2018-10-13T19:06:40.435+0530    restoring up to 2 collections in parallel
2018-10-13T19:06:40.435+0530    starting restore routine with id=1
2018-10-13T19:06:40.435+0530    starting restore routine with id=0
2018-10-13T19:06:40.435+0530    reading metadata for docdb1013.users from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/users.metadata.json
2018-10-13T19:06:40.435+0530    creating collection docdb1013.users using options from metadata
2018-10-13T19:06:40.435+0530    using collection options: bson.D{bson.DocElem{Name:"idIndex", Value:mongorestore.IndexDocument{Options:bson.M{"name":"_id_", "ns":"docdb1013.users"}, Key:bson.D{bson.DocElem{Name:"_id", Value:1}}, PartialFilterExpression:bson.D(nil)}}}
2018-10-13T19:06:40.460+0530    reading metadata for docdb1013.doccollect from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/doccollect.metadata.json
2018-10-13T19:06:40.461+0530    creating collection docdb1013.doccollect using options from metadata
2018-10-13T19:06:40.461+0530    using collection options: bson.D{bson.DocElem{Name:"idIndex", Value:mongorestore.IndexDocument{Options:bson.M{"name":"_id_", "ns":"docdb1013.doccollect"}, Key:bson.D{bson.DocElem{Name:"_id", Value:1}}, PartialFilterExpression:bson.D(nil)}}}
2018-10-13T19:06:40.462+0530    restoring docdb1013.users from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/users.bson
2018-10-13T19:06:40.463+0530    using 1 insertion workers
2018-10-13T19:06:40.504+0530    no indexes to restore
2018-10-13T19:06:40.504+0530    finished restoring docdb1013.users (40 documents)
2018-10-13T19:06:40.504+0530    reading metadata for docdb1013.Today from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/Today.metadata.json
2018-10-13T19:06:40.505+0530    creating collection docdb1013.Today using options from metadata
2018-10-13T19:06:40.505+0530    using collection options: bson.D{bson.DocElem{Name:"idIndex", Value:mongorestore.IndexDocument{Options:bson.M{"name":"_id_", "ns":"docdb1013.Today"}, Key:bson.D{bson.DocElem{Name:"_id", Value:1}}, PartialFilterExpression:bson.D(nil)}}}
2018-10-13T19:06:40.505+0530    restoring docdb1013.doccollect from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/doccollect.bson
2018-10-13T19:06:40.506+0530    using 1 insertion workers
2018-10-13T19:06:40.535+0530    no indexes to restore
2018-10-13T19:06:40.535+0530    finished restoring docdb1013.doccollect (5 documents)
2018-10-13T19:06:40.535+0530    reading metadata for docdb1013.doccollect4 from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/doccollect4.metadata.json
2018-10-13T19:06:40.535+0530    creating collection docdb1013.doccollect4 using options from metadata
2018-10-13T19:06:40.535+0530    using collection options: bson.D{bson.DocElem{Name:"capped", Value:true}, bson.DocElem{Name:"size", Value:200192}, bson.DocElem{Name:"idIndex", Value:mongorestore.IndexDocument{Options:bson.M{"name":"_id_", "ns":"docdb1013.doccollect4"}, Key:bson.D{bson.DocElem{Name:"_id", Value:1}}, PartialFilterExpression:bson.D(nil)}}}
2018-10-13T19:06:40.536+0530    restoring docdb1013.Today from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/Today.bson
2018-10-13T19:06:40.542+0530    using 1 insertion workers
2018-10-13T19:06:40.563+0530    no indexes to restore
2018-10-13T19:06:40.563+0530    finished restoring docdb1013.Today (1 document)
2018-10-13T19:06:40.563+0530    reading metadata for docdb1013.indx-doc1 from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/indx-doc1.metadata.json
2018-10-13T19:06:40.563+0530    creating collection docdb1013.indx-doc1 using options from metadata
2018-10-13T19:06:40.563+0530    using collection options: bson.D{bson.DocElem{Name:"idIndex", Value:mongorestore.IndexDocument{Options:bson.M{"name":"_id_", "ns":"docdb1013.indx-doc1"}, Key:bson.D{bson.DocElem{Name:"_id", Value:1}}, PartialFilterExpression:bson.D(nil)}}}
2018-10-13T19:06:40.563+0530    restoring docdb1013.doccollect4 from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/doccollect4.bson
2018-10-13T19:06:40.582+0530    using 1 insertion workers
2018-10-13T19:06:40.583+0530    no indexes to restore
2018-10-13T19:06:40.583+0530    finished restoring docdb1013.doccollect4 (0 documents)
2018-10-13T19:06:40.583+0530    reading metadata for docdb1013.mycoll from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/mycoll.metadata.json
2018-10-13T19:06:40.583+0530    creating collection docdb1013.mycoll using options from metadata
2018-10-13T19:06:40.583+0530    using collection options: bson.D{bson.DocElem{Name:"capped", Value:true}, bson.DocElem{Name:"size", Value:100096}, bson.DocElem{Name:"idIndex", Value:mongorestore.IndexDocument{Options:bson.M{"name":"_id_", "ns":"docdb1013.mycoll"}, Key:bson.D{bson.DocElem{Name:"_id", Value:1}}, PartialFilterExpression:bson.D(nil)}}}
2018-10-13T19:06:40.602+0530    restoring docdb1013.indx-doc1 from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/indx-doc1.bson
2018-10-13T19:06:40.604+0530    using 1 insertion workers
2018-10-13T19:06:40.605+0530    no indexes to restore
2018-10-13T19:06:40.605+0530    finished restoring docdb1013.indx-doc1 (0 documents)
2018-10-13T19:06:40.605+0530    ending restore routine with id=1, no more work to do
2018-10-13T19:06:40.629+0530    restoring docdb1013.mycoll from /yis/mdashok/full_db_ashokdb_user_reportsUser/ashokdb/mycoll.bson
2018-10-13T19:06:40.632+0530    using 1 insertion workers
2018-10-13T19:06:40.632+0530    no indexes to restore
2018-10-13T19:06:40.632+0530    finished restoring docdb1013.mycoll (0 documents)
2018-10-13T19:06:40.632+0530    ending restore routine with id=0, no more work to do
2018-10-13T19:06:40.632+0530    done
[mdashok@MongoDB ashokdb]$


MONGOEXPORT

  • Take a backup of a collection using mongoexport command utility with csv format. we see the content of the backup file
  • But in *.bson format we cannot see the backup content.
[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$ mongoexport --db docdb --out docdb_doccollect.csv --collection doccollect -vvvvvv
2018-10-13T19:22:13.428+0530    will listen for SIGTERM, SIGINT, and SIGKILL
2018-10-13T19:22:13.448+0530    connected to: localhost
2018-10-13T19:22:13.450+0530    exported 5 records
[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$


[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$ ls -ltr
total 4
-rw-r--r--. 1 mdashok mongodb 862 Oct 13 19:22 docdb_doccollect.csv
[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$


[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$ cat docdb_doccollect.csv
{"_id":{"$oid":"5bb0bd9aaf35aafba1581136"},"title":"MongoDB doc1","description":"MongoDB document 1","by":"Vimal","tags":["mongodb","NoSQLDB","DocDB","database"],"likes":100.0}
{"_id":{"$oid":"5bb0bd9eaf35aafba1581137"},"title":"MongoDB doc1","description":"MongoDB document 1","by":"ashok","tags":["mongodb","NoSQLDB","DocDB","database"],"likes":100.0}
{"_id":{"$oid":"5bb0bda4af35aafba1581138"},"title":"MongoDB doc1","description":"MongoDB document 1","by":"ashok","tags":["mongodb","NoSQLDB","DocDB","database"],"likes":100.0}
{"_id":{"$oid":"5bb0bda7af35aafba1581139"},"title":"casandra doc1","description":"NoSQLDB","by":"Ashok","tags":["NoSQL","DocDB","NotOnlySQL"],"likes":100.0}
{"_id":{"$oid":"5bb5f5deded3edb1e4b4f5a7"},"title":"indx-doc1","description":"MongoDB document 1","by":"Vimal","tags":["mongodb","NoSQLDB","DocDB","database"],"likes":100.0}
[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$

JSON format backup

[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$ mongoexport --db docdb --out docdb_doccollect.json --collection doccollect -vvvvvv
2018-10-13T20:16:10.947+0530    will listen for SIGTERM, SIGINT, and SIGKILL
2018-10-13T20:16:10.950+0530    connected to: localhost
2018-10-13T20:16:10.951+0530    exported 5 records



[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$ ls -ltr
-rw-r--r--. 1 mdashok mongodb 862 Oct 13 20:16 docdb_doccollect.json

[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$



JSON format backup with pretty option



[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$ mongoexport --db docdb --out docdb_doccollect.json --collection doccollect -vvvvvv --jsonArray --pretty


2018-10-13T20:20:08.318+0530    will listen for SIGTERM, SIGINT, and SIGKILL
2018-10-13T20:20:08.320+0530    connected to: localhost
2018-10-13T20:20:08.321+0530    exported 5 records
[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$

[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$ cat docdb_doccollect.json
[{
        "_id": {
                "$oid": "5bb0bd9aaf35aafba1581136"
        },
        "title": "MongoDB doc1",
        "description": "MongoDB document 1",
        "by": "Vimal",
        "tags": [
                "mongodb",
                "NoSQLDB",
                "DocDB",
                "database"
        ],
        "likes": 100.0
},
{
        "_id": {
                "$oid": "5bb0bd9eaf35aafba1581137"
        },
        "title": "MongoDB doc1",
        "description": "MongoDB document 1",
        "by": "ashok",
        "tags": [
                "mongodb",
                "NoSQLDB",
                "DocDB",
                "database"
        ],
        "likes": 100.0
},
{
        "_id": {
                "$oid": "5bb0bda4af35aafba1581138"
        },
        "title": "MongoDB doc1",
        "description": "MongoDB document 1",
        "by": "ashok",
        "tags": [
                "mongodb",
                "NoSQLDB",
                "DocDB",
                "database"
        ],
        "likes": 100.0
},
{
        "_id": {
                "$oid": "5bb0bda7af35aafba1581139"
        },
        "title": "casandra doc1",
        "description": "NoSQLDB",
        "by": "Ashok",
        "tags": [
                "NoSQL",
                "DocDB",
                "NotOnlySQL"
        ],
        "likes": 100.0
},
{
        "_id": {
                "$oid": "5bb5f5deded3edb1e4b4f5a7"
        },
        "title": "indx-doc1",
        "description": "MongoDB document 1",
        "by": "Vimal",
        "tags": [
                "mongodb",
                "NoSQLDB",
                "DocDB",
                "database"
        ],
        "likes": 100.0
}]
[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$

[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$ mongoexport --db ashokdb --out ashokdb_doccollect_fields.json  --collection doccollect -vvvvvv  --jsonArray --pretty --fields title,by
2018-10-13T21:12:15.391+0530    will listen for SIGTERM, SIGINT, and SIGKILL
2018-10-13T21:12:15.393+0530    connected to: localhost
2018-10-13T21:12:15.394+0530    exported 5 records

[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$


mdashok@MongoDB EXPORT_IMPORT_BACKUP]$ cat ashokdb_doccollect_fields.json
[{
        "_id": {
                "$oid": "5bb0bd9aaf35aafba1581136"
        },
        "title": "MongoDB doc1",
        "by": "Vimal"
},
{
        "_id": {
                "$oid": "5bb0bd9eaf35aafba1581137"
        },
        "title": "MongoDB doc1",
        "by": "ashok"
},
{
        "_id": {
                "$oid": "5bb0bda4af35aafba1581138"
        },
        "title": "MongoDB doc1",
        "by": "ashok"
},
{
        "_id": {
                "$oid": "5bb0bda7af35aafba1581139"
        },
        "title": "casandra doc1",
        "by": "Ashok"
},
{
        "_id": {
                "$oid": "5bb5f5deded3edb1e4b4f5a7"
        },
        "title": "indx-doc1",
        "by": "Vimal"
}]


mdashok@MongoDB EXPORT_IMPORT_BACKUP]$ mongoexport --db ashokdb --out ashokdb_doccollect_fields.csv  --collection doccollect -vvvvvv  --jsonArray --pretty --fields title,by

[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$ cat ashokdb_doccollect_fields.csv
[{
        "_id": {
                "$oid": "5bb0bd9aaf35aafba1581136"
        },
        "title": "MongoDB doc1",
        "by": "Vimal"
},
{
        "_id": {
                "$oid": "5bb0bd9eaf35aafba1581137"
        },
        "title": "MongoDB doc1",
        "by": "ashok"
},
{
        "_id": {
                "$oid": "5bb0bda4af35aafba1581138"
        },
        "title": "MongoDB doc1",
        "by": "ashok"
},
{
        "_id": {
                "$oid": "5bb0bda7af35aafba1581139"
        },
        "title": "casandra doc1",
        "by": "Ashok"
},
{
        "_id": {
                "$oid": "5bb5f5deded3edb1e4b4f5a7"
        },
        "title": "indx-doc1",
        "by": "Vimal"
}]

[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$



MONGOIMPORT


Restore a collection from backup using mongoimport 

Check the records count before delete it#

MongoDB Enterprise > db.doccollect.find();
{ "_id" : ObjectId("5bb0bd9aaf35aafba1581136"), "title" : "MongoDB doc1", "description" : "MongoDB document 1", "by" : "Vimal", "tags" : [ "mongodb", "NoSQLDB", "DocDB", "database" ], "likes" : 100 }
{ "_id" : ObjectId("5bb0bd9eaf35aafba1581137"), "title" : "MongoDB doc1", "description" : "MongoDB document 1", "by" : "ashok", "tags" : [ "mongodb", "NoSQLDB", "DocDB", "database" ], "likes" : 100 }
{ "_id" : ObjectId("5bb0bda4af35aafba1581138"), "title" : "MongoDB doc1", "description" : "MongoDB document 1", "by" : "ashok", "tags" : [ "mongodb", "NoSQLDB", "DocDB", "database" ], "likes" : 100 }
{ "_id" : ObjectId("5bb0bda7af35aafba1581139"), "title" : "casandra doc1", "description" : "NoSQLDB", "by" : "Ashok", "tags" : [ "NoSQL", "DocDB", "NotOnlySQL" ], "likes" : 100 }
{ "_id" : ObjectId("5bb5f5deded3edb1e4b4f5a7"), "title" : "indx-doc1", "description" : "MongoDB document 1", "by" : "Vimal", "tags" : [ "mongodb", "NoSQLDB", "DocDB", "database" ], "likes" : 100 }


remove the records from collection 

MongoDB Enterprise > db.doccollect.remove({});
WriteResult({ "nRemoved" : 5 })

MongoDB Enterprise >


MongoDB Enterprise > db.doccollect.find();
MongoDB Enterprise >


[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$ mongoimport --db docdb --file docdb_doccollect.csv --collection docollect -vvvvvv

2018-10-13T20:31:07.988+0530    using 1 decoding workers
2018-10-13T20:31:07.988+0530    using 1 insert workers
2018-10-13T20:31:07.988+0530    filesize: 862 bytes
2018-10-13T20:31:07.988+0530    using fields:
2018-10-13T20:31:08.003+0530    will listen for SIGTERM, SIGINT, and SIGKILL
2018-10-13T20:31:08.014+0530    connected to: localhost
2018-10-13T20:31:08.014+0530    ns: docdb.docollect
2018-10-13T20:31:08.014+0530    connected to node type: standalone
2018-10-13T20:31:08.021+0530    standalone server: setting write concern w to 1
2018-10-13T20:31:08.021+0530    using write concern: w='1', j=false, fsync=false, wtimeout=0
2018-10-13T20:31:08.021+0530    standalone server: setting write concern w to 1
2018-10-13T20:31:08.021+0530    using write concern: w='1', j=false, fsync=false, wtimeout=0
2018-10-13T20:31:08.028+0530    got line: [{_id [{$oid 5bb0bd9aaf35aafba1581136}]} {title MongoDB doc1} {description MongoDB document 1} {by Vimal} {tags [mongodb NoSQLDB DocDB database]} {likes 100}]
2018-10-13T20:31:08.028+0530    got extended line: bson.D{bson.DocElem{Name:"_id", Value:"[\xb0\xbd\x9a\xaf5\xaa\xfb\xa1X\x116"}, bson.DocElem{Name:"title", Value:"MongoDB doc1"}, bson.DocElem{Name:"description", Value:"MongoDB document 1"}, bson.DocElem{Name:"by", Value:"Vimal"}, bson.DocElem{Name:"tags", Value:[]interface {}{"mongodb", "NoSQLDB", "DocDB", "database"}}, bson.DocElem{Name:"likes", Value:100}}
2018-10-13T20:31:08.028+0530    got line: [{_id [{$oid 5bb0bd9eaf35aafba1581137}]} {title MongoDB doc1} {description MongoDB document 1} {by ashok} {tags [mongodb NoSQLDB DocDB database]} {likes 100}]
2018-10-13T20:31:08.028+0530    got extended line: bson.D{bson.DocElem{Name:"_id", Value:"[\xb0\xbd\x9e\xaf5\xaa\xfb\xa1X\x117"}, bson.DocElem{Name:"title", Value:"MongoDB doc1"}, bson.DocElem{Name:"description", Value:"MongoDB document 1"}, bson.DocElem{Name:"by", Value:"ashok"}, bson.DocElem{Name:"tags", Value:[]interface {}{"mongodb", "NoSQLDB", "DocDB", "database"}}, bson.DocElem{Name:"likes", Value:100}}
2018-10-13T20:31:08.028+0530    got line: [{_id [{$oid 5bb0bda4af35aafba1581138}]} {title MongoDB doc1} {description MongoDB document 1} {by ashok} {tags [mongodb NoSQLDB DocDB database]} {likes 100}]
2018-10-13T20:31:08.028+0530    got extended line: bson.D{bson.DocElem{Name:"_id", Value:"[\xb0\xbd\xa4\xaf5\xaa\xfb\xa1X\x118"}, bson.DocElem{Name:"title", Value:"MongoDB doc1"}, bson.DocElem{Name:"description", Value:"MongoDB document 1"}, bson.DocElem{Name:"by", Value:"ashok"}, bson.DocElem{Name:"tags", Value:[]interface {}{"mongodb", "NoSQLDB", "DocDB", "database"}}, bson.DocElem{Name:"likes", Value:100}}
2018-10-13T20:31:08.028+0530    got line: [{_id [{$oid 5bb0bda7af35aafba1581139}]} {title casandra doc1} {description NoSQLDB} {by Ashok} {tags [NoSQL DocDB NotOnlySQL]} {likes 100}]
2018-10-13T20:31:08.028+0530    got extended line: bson.D{bson.DocElem{Name:"_id", Value:"[\xb0\xbd\xa7\xaf5\xaa\xfb\xa1X\x119"}, bson.DocElem{Name:"title", Value:"casandra doc1"}, bson.DocElem{Name:"description", Value:"NoSQLDB"}, bson.DocElem{Name:"by", Value:"Ashok"}, bson.DocElem{Name:"tags", Value:[]interface {}{"NoSQL", "DocDB", "NotOnlySQL"}}, bson.DocElem{Name:"likes", Value:100}}
2018-10-13T20:31:08.028+0530    got line: [{_id [{$oid 5bb5f5deded3edb1e4b4f5a7}]} {title indx-doc1} {description MongoDB document 1} {by Vimal} {tags [mongodb NoSQLDB DocDB database]} {likes 100}]
2018-10-13T20:31:08.028+0530    got extended line: bson.D{bson.DocElem{Name:"_id", Value:"[\xb5\xf5\xde\xde\xd3\xed\xb1\xe4\xb4\xf5\xa7"}, bson.DocElem{Name:"title", Value:"indx-doc1"}, bson.DocElem{Name:"description", Value:"MongoDB document 1"}, bson.DocElem{Name:"by", Value:"Vimal"}, bson.DocElem{Name:"tags", Value:[]interface {}{"mongodb", "NoSQLDB", "DocDB", "database"}}, bson.DocElem{Name:"likes", Value:100}}
2018-10-13T20:31:08.072+0530    imported 5 documents
[mdashok@MongoDB EXPORT_IMPORT_BACKUP]$



MongoDB Enterprise > db
docdb
MongoDB Enterprise > db.doccollect.find();
{ "_id" : ObjectId("5bb0bd9aaf35aafba1581136"), "title" : "MongoDB doc1", "description" : "MongoDB document 1", "by" : "Vimal", "tags" : [ "mongodb", "NoSQLDB", "DocDB", "database" ], "likes" : 100 }
{ "_id" : ObjectId("5bb0bd9eaf35aafba1581137"), "title" : "MongoDB doc1", "description" : "MongoDB document 1", "by" : "ashok", "tags" : [ "mongodb", "NoSQLDB", "DocDB", "database" ], "likes" : 100 }
{ "_id" : ObjectId("5bb0bda4af35aafba1581138"), "title" : "MongoDB doc1", "description" : "MongoDB document 1", "by" : "ashok", "tags" : [ "mongodb", "NoSQLDB", "DocDB", "database" ], "likes" : 100 }
{ "_id" : ObjectId("5bb0bda7af35aafba1581139"), "title" : "casandra doc1", "description" : "NoSQLDB", "by" : "Ashok", "tags" : [ "NoSQL", "DocDB", "NotOnlySQL" ], "likes" : 100 }
{ "_id" : ObjectId("5bb5f5deded3edb1e4b4f5a7"), "title" : "indx-doc1", "description" : "MongoDB document 1", "by" : "Vimal", "tags" : [ "mongodb", "NoSQLDB", "DocDB", "database" ], "likes" : 100 }
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise >
MongoDB Enterprise >


Step by Step YugabyteDB 2.11 (Open Source) Distributed DB - Multi-node Cluster Setup on RHEL

Scope - ·        Infrastructure planning and requirement for installation of the multi-node cluster database ·        Prerequisites Software...