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

[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]

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
[code lang=”shell”]
[[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)
[/code]

[code lang=”shell”]
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.
[/code]

Solution

[code lang=”shell”]
vim /etc/security/limits.d/90-nproc.conf
[/code]
Then put in
[code lang=”shell”]
mongod soft nproc 64000
[/code]
and
[code lang=”shell”]
reboot
[/code]

Show Image Size in Terminal or Shell

The easiest way to show the file size in Terminal in Mac or Linux.
[code lang=”bash”]
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 720×468 720×468+0+0 8-bit sRGB 59.8KB 0.000u 0:00.009
Justins-MacBook-Pro:jpg juzhax$
[/code]

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
[code lang=”bash”]
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
[/code]

The first argument should be the extension of the backup file. The correct way is
[code lang=”bash”]
Justins-MacBook-Pro:2 juzhax$ sed -i ‘.bak’ ‘s/old_text/new_text/g’ example.txt
[/code]

or

[code lang=”bash”]
Justins-MacBook-Pro:2 juzhax$ sed -i ‘.original’ ‘s/old_text/new_text/g’ example.txt
[/code]

If you don’t want any backup file, you can do like this.
[code lang=”bash”]
Justins-MacBook-Pro:2 juzhax$ sed -i ” ‘s/old_text/new_text/g’ example.txt
[/code]