Install mongodb using yum CentOS-7.x

install mongodb-3.4.1 community-edition

create repo file mongo on /etc/yum.repos.d/

[root@dbserver1]# vi /etc/yum.repos.d/mongodb.repo

[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
[root@dbserver1]# yum repolist
[root@dbserver1]# yum -y install mongodb-org.x86_64

If you are using SELinux, you must configure SELinux to allow MongoDB to start on Red Hat Linux-based systems (Red Hat Enterprise Linux or CentOS Linux).

Disable SELinux by setting the SELINUX setting to disabled in /etc/selinux/config.

SELINUX=disabled

start service mongodb

[root@dbserver1]# systemctl start mongod

check status running or no mongod service

[root@dbserver1]# systemctl status mongod

● mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/usr/lib/systemd/system/mongod.service; enabled; vendor preset: disabled)
   Active: active (running) since Sel 2017-01-10 17:56:21 WIB; 2 weeks 6 days ago
     Docs: https://docs.mongodb.org/manual
  Process: 31686 ExecStartPre=/usr/bin/chmod 0755 /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 31681 ExecStartPre=/usr/bin/chown mongod:mongod /var/run/mongodb (code=exited, status=0/SUCCESS)
  Process: 31679 ExecStartPre=/usr/bin/mkdir -p /var/run/mongodb (code=exited, status=0/SUCCESS)
 Main PID: 31701 (mongod)
   Memory: 6.1G
   CGroup: /system.slice/mongod.service
           └─31701 /usr/bin/mongod --quiet -f /etc/mongod.conf run

Jan 10 17:56:21 dbserver1.example.com systemd[1]: Starting High-performance, schema-free document-oriented database...
Jan 10 17:56:21 dbserver1.example.com systemd[1]: Started High-performance, schema-free document-oriented database.
Jan 10 17:56:21 dbserver1.example.com mongod[31690]: about to fork child process, waiting until server is ready for connections.
Jan 10 17:56:21 dbserver1.example.com mongod[31690]: forked process: 31701
Jan 10 17:56:22 dbserver1.example.com mongod[31690]: child process started successfully, parent exiting

Print query mongodb to json format

this is sample way how to print query mongodb to json format

mongo –host IP_address/dbname -u user_name -p password –eval ‘printjson(Query_mongo)’ > output.json

mongo --host 192.168.10.20/products -u ericks -p januari2017 --eval 'printjson(db.getCollection('transaction_shares').find({transaction_time: {$lt: ISODate("2016-12-07"),$gte: ISODate("2016-12-01")}},{_id: 0, transaction_id: 1, variables: 1, transaction_time: 1}))' > query_products.json

hope this article help you