Last updated on May 19th, 2016 at 02:51 am
I would like to query the data that I need only from a server to another server, and I just use one line of command in linux shell
[code lang=”shell”]
mongoexport -h fromHost.com -d fromDB -c fromCollection -q ‘{ count: { $gte: 1 } }’ | mongoimport -h toHost.com -d toNewDB -c toNewCollection
[/code]
If your date is many GB, you can run it in background using nohup
[code lang=”shell”]
nohup "mongoexport -h fromHost.com -d fromDB -c fromCollection -q ‘{ count: { \$gte: 1 } }’ | mongoimport -h toHost.com -d toNewDB -c toNewCollection" &
[/code]
If you want to view the current process
[code lang=”shell”]
tail nohup.out -f
[/code]
It will output something like
[code lang=”shell”]
2016-05-17T02:34:47.822+0700 imported 1431218 documents
2016-05-17T02:36:40.240+0700 connected to: localhost
2016-05-17T02:36:40.243+0700 connected to: db.fromHost.com
2016-05-17T02:36:41.244+0700 db.collection 1000
2016-05-17T02:36:42.243+0700 db.collection 56000
2016-05-17T02:36:43.239+0700 db.collection0517 11.5 MB
2016-05-17T02:36:43.243+0700 db.collection 88000
2016-05-17T02:36:44.244+0700 db.collection 128000
2016-05-17T02:36:45.243+0700 db.collection 160000
2016-05-17T02:36:46.239+0700 db.collection0517 24.4 MB
…..
…..
[/code]