mongoexport and mongoimport with query from one host to one host

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

mongoexport -h fromHost.com -d fromDB -c fromCollection -q '{ count: { $gte: 1 } }' | mongoimport -h toHost.com -d toNewDB -c toNewCollection

If your date is many GB, you can run it in background using nohup

nohup "mongoexport -h fromHost.com -d fromDB -c fromCollection -q '{ count: { \$gte: 1 } }' | mongoimport -h toHost.com -d toNewDB -c toNewCollection" &

If you want to view the current process

tail nohup.out -f

It will output something like

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
.....
.....

WARNING: soft rlimits too low. rlimits set to 4096 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.

I’ve received this error while starting mongo in shell while installing on

[[email protected] ~]# mongod --version
db version v3.2.3
git version: b326ba837cf6f49d65c2f85e1b70f6f31ece7937
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel70
    distarch: x86_64
    target_arch: x86_64
[[email protected] ~]# mongo --version
MongoDB shell version: 3.2.3
CentOS Linux release 7.2.1511 (Core)
WARNING: soft rlimits too low. rlimits set to 4096 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.

Solution

vim /etc/security/limits.d/90-nproc.conf

Then put in

mongod     soft    nproc     64000

and

reboot

Show Image Size in Terminal or Shell

The easiest way to show the file size in Terminal in Mac or Linux.

ustins-MacBook-Pro:jpg juzhax$ file 001.jpg
001.jpg: JPEG image data, EXIF standard
Justins-MacBook-Pro:jpg juzhax$ identify 001.jpg
001.jpg JPEG 720x468 720x468+0+0 8-bit sRGB 59.8KB 0.000u 0:00.009
Justins-MacBook-Pro:jpg juzhax$

command c expects followed by text error in Mac

You received error from the sed command in Mac, because the argument in mac is different.
If you type in Mac terminal, you may receive error like this

Justins-MacBook-Pro:2 juzhax$ sed -i 's/old_text/new_text/g' example.txt
sed: 1: "config.php": command c expects \ followed by text

The first argument should be the extension of the backup file. The correct way is

Justins-MacBook-Pro:2 juzhax$ sed -i '.bak' 's/old_text/new_text/g' example.txt

or

Justins-MacBook-Pro:2 juzhax$ sed -i '.original' 's/old_text/new_text/g' example.txt

If you don’t want any backup file, you can do like this.

Justins-MacBook-Pro:2 juzhax$ sed -i '' 's/old_text/new_text/g' example.txt