Difference between revisions of "MongoDB"

From Wasya Wiki
Jump to: navigation, search
(Created page with "== Install MongoDB on ubuntu == From: https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E...")
 
Line 6: Line 6:
 
  sudo apt-get update -y
 
  sudo apt-get update -y
 
  sudo apt-get install -y mongodb-org
 
  sudo apt-get install -y mongodb-org
 +
 +
== Count Documents ==
 +
<pre>
 +
db.collection.aggregate(
 +
  [
 +
    { $group: { _id: null, count: { $sum: 1 } } }
 +
  ]
 +
)
 +
</pre>

Revision as of 19:40, 5 September 2017

Install MongoDB on ubuntu

From: https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update -y
sudo apt-get install -y mongodb-org

Count Documents

db.collection.aggregate(
  [
    { $group: { _id: null, count: { $sum: 1 } } }
  ]
)