0% found this document useful (0 votes)
88 views10 pages

MongoDB Cheat Sheet

This is a book containing all method to CRUD operations in MongoDb.

Uploaded by

DANIEL FADAMITAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
88 views10 pages

MongoDB Cheat Sheet

This is a book containing all method to CRUD operations in MongoDb.

Uploaded by

DANIEL FADAMITAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
1 | @CODE.CLASH ) MongobDB : Cheat Sheet2 @CODE.CLASH |) Hey Everyone ¥ This Post includes a MongoDB cheat sheet to make it easy for our followers to work with MongoDB. Link in bio get cheat sheet pdf. Do Like, save and Share This Post If You Found This Helpful. , 7? a as LL sii)i} @CODE.CLASH Insert Row Cee eee used pets Ca a Dean Coan re ee tags: ['news', ‘events'], ria | DeLee Ln er eee a , date: Date() 1) Insert Multiple Rows Coe ee Cries dal f Persea Ce Ne Sas category: ‘Technology’, date: Date() hy i cots t rao tan on NS Cs aa category: 'News', date: Date() a Ne a Coie nee Lue date: Date() ui 1) Next —>Get All Rows @CODE.CLASH db.posts.find() Get All Rows Formatted db. posts. find().pretty() Find Rows db.posts.find({ category: ‘News’ }) Tole a Co) Ame) db.posts.find().sort({ title: 1 }).pretty() // desc db.posts.find().sort({ title: -1 }).pretty() Count Rows db.posts.find().count() db.posts.find({ category: ‘news’ }).count()Show All Databases @CODE.CLASH show dbs Show Current Database db Create Or Switch Database use acme Ly coy) db. dropDatabase() Create Collection db.createCollection( ‘posts’ ) Show Collections show collections6 Limit Rows db.posts.find().limit(2).pretty() Chaining db.posts.find().1imit(2).sort({ title: 1 }).pretty() Find One Row db.posts.findOne({ category: ‘News’ }) Foreach db.posts.find().forEach(function(doc) { print("Blog Post: " + doc.title) 1) Find Specific Fields db.posts.find({ title: ‘Post One’ }, { title: 1, EO allay 1D), Update Row db.posts.update({ title: 'Post Two’ }, pecs Hoan Pe Sm ania Sia date: Date() is { aaa 2) Update Specific Field db.posts.update({ title: ‘Post Two’ }, i aang PrN ae a a eeu Cin a 1) Increment Field ($inc) db.posts.update({ title: ‘Post Two’ }, { Sine: { pt Tray } 3)8 @CODE.CLASH Rename Field db.posts.update({ title: ‘Post Two' }, Srename: { likes: ‘views’ 2 3) pl=\ (el eeH Cel] db.posts.remove({ title: ‘Post Four' }) Sub-Documents db.posts.update({ title: ‘Post One’ }, { lean Lame { Der ea Tec Sec LOUn date: Date() in { Der Aa ae ec Yas ark date: Date() u ] z 19) Next —>t) @CODE.CLASH Find By Element in Array db. posts. find({ comments: { RSet Peco m reer Add Index db.posts.createIndex({ title: ‘text’ }) Text Search COM eeu Let Stext: { Cee ie a } ) Greater & Less Than CON meee oa ee aS) db.posts.find({ views: { Sgte: 7 } }) Cer UCM e Ce ese tae a) db.posts.find({ views: { Slte: 7 } }) Ls il [email protected] |) Check Out My Profile For Such Excellent Posts On Web Development. IMTIYAZ NANDASANIYA

You might also like