Narrative
IncyWincyWebApp stores some of its persistent data on MongoDB.
Dave, the developer wants the data for user analytics purposes only. So he approaches Adam, the MongoDB admin
Dave: "Hey Adam,I require the
sessions and
locations collections from
users database, and preferably on a separate node"
Adam offering a solution: "Ok, we can selectively restore only those collections from the backup, on a different target."
Dave: "That would be great ! Thanks."
Given source replica set and target node are running |
with configuration |
source {unsecureSrcNode} on port {unsecureSrcPort} , target {unsecureTgtNode} on port {unsecureTgtPort} |
1. Given an existing database
run mongo command on |
source |
Comments |
use database |
users |
|
run |
db.createCollection("profile") |
|
run |
db.profile.insert({name:"One"}) |
|
run |
db.profile.save({name:"Two"}) |
|
run |
db.sessions.insert({sessionId:"session1"}) |
|
run |
db.locations.insert({place:"Pune"}) |
|
run |
db.locations.insert({place:"London"}) |
|
use database |
transactions |
|
run |
db.orders.insert({order:"One"}) |
|
run |
db.orders.save({order:"Two"}) |
|
2. Run Backup Utility
Open terminal |
and run |
backup -s {unsecureSrcNode} --port={unsecureSrcPort} -f {file} |
and show |
stdout |
and ensure |
stdout |
contains |
Process started |
3. Run Restore Utility using Namespace
Open terminal |
and run |
restore -d {unsecureTgtNode} --port={unsecureTgtPort} -f {file} --sNs=users.locations,users.sessions |
and show |
stdout |
and ensure |
stdout |
contains |
Process started |
4. Ensure Expected Results
Checking documents of database users
Ensure source and target has
|
run in database |
users |
query |
db.profile.count() |
and cleanup databases |
false |
source value | destination value |
2 | 0 |
Ensuring target is consistent with source
|
find documents for collection |
sessions |
in database |
users |
where |
null |
and cleanup databases |
false |
source value | destination value |
{ "sessionId" : "session1"} | { "sessionId" : "session1"} |
Ensuring target is consistent with source
|
find documents for collection |
locations |
in database |
users |
where |
null |
and cleanup databases |
true |
source value | destination value |
{ "place" : "Pune"} | { "place" : "Pune"} |
{ "place" : "London"} | { "place" : "London"} |
Checking documents of database transactions
Ensure source and target has
|
run in database |
transactions |
query |
db.orders.count() |
and cleanup databases |
true |
source value | destination value |
2 | 0 |