Mongodb Query Cheat Sheet

Posted on  by 



  1. Mongodb Query Cheat Sheet Download
  2. Mongodb Query Tutorial


  • PDF Link: cheatsheet-mongodb-A4.pdf, Category: Tools
  • Blog URL: https://cheatsheet.dennyzhang.com/cheatsheet-mongodb-A4
  • Related posts: Prometheus CheatSheet, Nagios CheatSheet, #denny-cheatsheets

File me Issues or star this repo.

MongoDB: Shell JavaScript Operations Cheat Sheet. Db.auth If running in secure mode. View Notes - Mongo Shell Cheat Sheet from IPD 451 at DePaul University. Shell cheat sheet for MongoDB version 2.4 Database Administration CRUD Queries Analytic Queries Command line tools Query. About this Cheat Sheet Basic Information The idea behind this is to have all (well, most) information from the above mentioned Tutorial immediately available in a very compact format. MongoDB Shell Commands Cheat Sheet. This is a Cheat Sheet for interacting with the Mongo Shell (mongo on your command line). This is for MongoDB Community Edition.

1.1 Mongodb Operation

NameSummary
Connect to mongodbmongo 192.168.75.108:12345/d_2003 -u u_2003 -p XXXX
Start mongomongod --config /etc/mongod.conf
Stop mongokill -15 <pid>; mongo --eval 'db.getSiblingDB('admin').shutdownServer()'
Mongo script get parametersmongo –eval “var day=’2013-07-26′” localhost:27017/shopex mongojs/update-index.js
Mongo data folder/var/lib/mongodb/journal
Export to json filemongoexport --db shopex --collection order --out collection.json
Import json filemongoimport --upsert --db shopex --collection order --file collection.json

1.2 Mongodb Basic

Mongodb query cheat sheet

Mongodb Query Cheat Sheet Download

NameSummary
Remove tabledb.kvstore.remove()
define stored proceduredb.system.js.save({_id:'addNumbers', value:function(x, y){ return x + y; }})
view stored proceduredb.system.js.find()
call stored proceduredb.eval('addNumbers(3, 4.2)')
Create recorddb.users.insert({'name':{'first':'refactor','last':'refactor2'},'age':24})
Update recorddb.users.update({'age':30}, {$set:{'age':31}});
Delete by filteringdb.users.remove({'age':30})
Loop cusrorwhile(s.hasNext()) printjson(s.next());
Loop arrayi=0; while(i < s.length) printjson(s[i++]);

1.3 Mongodb Query

Mongodb Query Tutorial

NameSummary
Basic querydb.users.find({“name”:{“first”:”refactor”,”last”:”refactor2″}})
Basic querydb.users.find({“name.first”:”refactor”})
great than / or equaldb.users.find({“age”:{“$gte”:20}})
not equaldb.users.find({“age”:{“$ne”:31}})
existsdb.users.find({“age”:{“$exists”:true}})
indb.users.find({“age”:{“$in”:[21,24]}})
not indb.users.find({“age”:{“$nin”:[21,23]}})
ordb.users.find({“$or”:[{“name.last”:”another”}, {“age”:31}]})
Count matched recordsdb.order.find({“created”:{“$regex”:”2013-07-12.*”}}).count()
db.users.find({“age”:{“$nin”:[21,23]}}).count()
query by offsetdb.users.find({“age”:{“$nin”:[21,23]}}).skip(1).limit(2)
sortdb.users.find().sort({“age”:24});
reverse orderdb.users.find().sort({“name.last”: -1})
db.users.find().forEach( function(u) { printjson(u); } );
mod 20db.users.find({“age”:{“$mod”:[20,4]}})
Parse string to floatparseFloat(v.availableConfirmFee, 10);
filter by “like”db.taobao.find({“created”:/2013-07-12.*/})
db.order.find({“created”:/2013-07-14.*/, “num”:{“$exists”:false}}).forEach( function(u) { printjson(u.tid); } );
db.order.find({“created”:{“$regex”:day}}).count();
db.order.distinct(“buyerNick”, {“created”:{“$regex”:day}}).length

1.4 More Resources





Coments are closed