Skip to content

Instantly share code, notes, and snippets.

@nailuoGG
Last active August 17, 2019 08:36
Show Gist options
  • Save nailuoGG/ded00ffac27a24f1370bd33fa98ebd81 to your computer and use it in GitHub Desktop.
Save nailuoGG/ded00ffac27a24f1370bd33fa98ebd81 to your computer and use it in GitHub Desktop.
[mongodb 文档集合] #mongodb #database

Bulk Write Operations

Bulk Write Operations — MongoDB Manual 3.6

try {
   db.characters.bulkWrite(
      [
         { insertOne :
            {
               "document" :
               {
                  "_id" : 4, "char" : "Dithras", "class" : "barbarian", "lvl" : 4
               }
            }
         },
         { insertOne :
            {
               "document" :
               {
                  "_id" : 5, "char" : "Taeln", "class" : "fighter", "lvl" : 3
               }
            }
         },
         { updateOne :
            {
               "filter" : { "char" : "Eldon" },
               "update" : { $set : { "status" : "Critical Injury" } }
            }
         },
         { deleteOne :
            { "filter" : { "char" : "Brisbane"} }
         },
         { replaceOne :
            {
               "filter" : { "char" : "Meldane" },
               "replacement" : { "char" : "Tanys", "class" : "oracle", "lvl" : 4 }
            }
         }
      ]
   );
}
catch (e) {
   print(e);
}

package list

Install MongoDB Community Edition on Red Hat Enterprise or CentOS Linux — MongoDB Manual 3.6

Package Name	Description
mongodb-org	A metapackage that will automatically install the four component packages listed below.
mongodb-org-server	Contains the mongod daemon and associated configuration and init scripts.
mongodb-org-mongos	Contains the mongos daemon.
mongodb-org-shell	Contains the mongo shell.
mongodb-org-tools	Contains the following MongoDB tools: mongoimport bsondump, mongodump, mongoexport, mongofiles, mongoperf, mongorestore, mongostat, and mongotop.
# create /etc/yum.repos.d/mongodb-org-3.6.repo
touch /etc/yum.repos.d/mongodb-org-3.6.repo
[mongodb-org-3.6]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc

install

sudo yum install -y mongodb-org

configure

  • data folder permission
  • selinux config

start mongodb

# start 
sudo service mongod start
# stop 
sudo service mongod stop
# restart 
sudo service mongod restart

verify mongodb start

/var/log/mongodb/mongod.log

start after reboot

sudo chkconfig mongod on

get tar.gz download link: MongoDB Download Center | MongoDB

# download
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.3.tgz
# extract file 
tar -zxvf mongodb-linux-x86_64-3.6.3.tgz
mkdir -p mongodb
cp -R -n mongodb-linux-x86_64-3.6.3/ mongodb

set path env

export PATH=<mongodb-install-directory>/bin:$PATH

run

# create data directory
mkdir -p /data/db
# set permission
sudo chown -R mongod:mongod  /data/db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment