SlideShare a Scribd company logo
Hacking the Shell Raw MongoDB (as you like it)Scott Hernandez – scott@10gen
What is the shell?
What is it good for?Debugging Queries/SyntaxTestingAdministrationScripting GlueNot for building apps, probably
The Bad: JS TypesNumbers Suck (but getting better)32/64bit signed (int/long) – 1.5.4>NumberLong(“”)Displayed funny in early versionsEverything is a 64bit fp (double)Dates are a challengenew Date(“1/1/1”)new ISODate(…)Not Date(“1/1/1”) -> string
The Bad: JS is SlowShellAlways Safe/GLELoops and updatesData conversionsServerIt pretty much applies here tooBe careful with numbers as well
Insert, Save, Update, RemoveDemo now for(i = 0; i <1000; i++) { db.test.insert({x:i, ts: new Date()}) }
Command Line--evalit/cursorPrinting valuesPass in a script
Loading ScriptsCommand lineload() – also runs
Run Commandsdb.runCommand({…})db.runCommand(“getLastError”)
Useful CommandsgetCmdLineOptspingisMasterreIndexshardingreplication
ProfilingsetProfilingLevel(lvl, <ms>)0: none1: time-based2: allgetProfilingLevel()Reading from profile collection>db.system.profile.find()
Help> help> help admin> help misc> db.help()> db.coll.help()
Expose FunctionsLeave off the () to see the function:> db.getSisterDBfunction (name) {    return this.getMongo().getDB(name);
Cool functionsprintjson -> tojsonforEach on array/query/cursor> [{x:1},{y:1}].forEach(function(x){printjson(x)}){ "x" : 1 }{ "y" : 1 }Object.bsonsizeObject.bsonsize(c.findOne({name:”scott”}))load(file)run(file)
Print all Indexesdb.getCollectionNames().forEach(function(x){	print(“Collection: “ + x);printjson(db[x].getIndexes());})
Getting the Biggest Docvar cursor = db.coll.find();var biggest=0;var doc = {};cursor.forEach(function (x) { var size = Object.bsonsize(x); 	if (size > biggest) { biggest=size; doc = x; }});
Cursors: it“it” global varfind automatically sets it
AliasesShow collections/tables
DBRefHas fetch()Easy to create
QuestionsThat’s all…folks!scott@10gen.com

More Related Content

Viewers also liked (14)

PDF
Webinar Slides: Become a MongoDB DBA (if you’re really a MySQL user)
Severalnines
 
PPTX
Webinar: An Enterprise Architect’s View of MongoDB
MongoDB
 
PPT
MongoDB Tick Data Presentation
MongoDB
 
PPTX
MongoDB
jsterce
 
PPT
A Brief MongoDB Intro
Scott Hernandez
 
PDF
MongoDB: Intro & Application for Big Data
Takahiro Inoue
 
PDF
Introduction to MongoDB
Justin Smestad
 
KEY
OSCON 2012 MongoDB Tutorial
Steven Francia
 
PDF
Query mechanisms for NoSQL databases
ArangoDB Database
 
PDF
Mongo DB
Edureka!
 
PDF
Intro To MongoDB
Alex Sharp
 
PPT
Introduction to MongoDB
Ravi Teja
 
PPTX
An Introduction To NoSQL & MongoDB
Lee Theobald
 
PDF
A Beginners Guide to noSQL
Mike Crabb
 
Webinar Slides: Become a MongoDB DBA (if you’re really a MySQL user)
Severalnines
 
Webinar: An Enterprise Architect’s View of MongoDB
MongoDB
 
MongoDB Tick Data Presentation
MongoDB
 
MongoDB
jsterce
 
A Brief MongoDB Intro
Scott Hernandez
 
MongoDB: Intro & Application for Big Data
Takahiro Inoue
 
Introduction to MongoDB
Justin Smestad
 
OSCON 2012 MongoDB Tutorial
Steven Francia
 
Query mechanisms for NoSQL databases
ArangoDB Database
 
Mongo DB
Edureka!
 
Intro To MongoDB
Alex Sharp
 
Introduction to MongoDB
Ravi Teja
 
An Introduction To NoSQL & MongoDB
Lee Theobald
 
A Beginners Guide to noSQL
Mike Crabb
 

Similar to MongoDB: Mastering the shell (20)

PPTX
Mastering the MongoDB Javascript Shell
Scott Hernandez
 
PPTX
Shell Tips & Tricks
MongoDB
 
PPTX
MongoDB Shell Tips & Tricks
MongoDB
 
PDF
Mongophilly shell-2011-04-26
kreuter
 
PPTX
Shell Tips and Tricks
MongoDB
 
PDF
Mastering the MongoDB Shell
MongoDB
 
PDF
Mongo Berlin - Mastering the Shell
MongoDB
 
PDF
Quick & Dirty & MEAN
Troy Miles
 
PPTX
MongoDB installation,CRUD operation & JavaScript shell
ShahDhruv21
 
KEY
MongoDB Command Line Tools
Rainforest QA
 
PDF
Mongo db halloween party
Andrea Balducci
 
PDF
MongoDB - An Introduction
sethfloydjr
 
PDF
Using MongoDB and Python
Mike Bright
 
PDF
2016 feb-23 pyugre-py_mongo
Michael Bright
 
PPTX
MongoDB
Bembeng Arifin
 
PPTX
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
PPTX
Introduction to MongoDB
MongoDB
 
PPTX
MongoDB basics & Introduction
Jerwin Roy
 
PDF
Mongodb
Thiago Veiga
 
PDF
Philadelphia MongoDB User Group - Your First MongoDB Application
Michael Lynn
 
Mastering the MongoDB Javascript Shell
Scott Hernandez
 
Shell Tips & Tricks
MongoDB
 
MongoDB Shell Tips & Tricks
MongoDB
 
Mongophilly shell-2011-04-26
kreuter
 
Shell Tips and Tricks
MongoDB
 
Mastering the MongoDB Shell
MongoDB
 
Mongo Berlin - Mastering the Shell
MongoDB
 
Quick & Dirty & MEAN
Troy Miles
 
MongoDB installation,CRUD operation & JavaScript shell
ShahDhruv21
 
MongoDB Command Line Tools
Rainforest QA
 
Mongo db halloween party
Andrea Balducci
 
MongoDB - An Introduction
sethfloydjr
 
Using MongoDB and Python
Mike Bright
 
2016 feb-23 pyugre-py_mongo
Michael Bright
 
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
Introduction to MongoDB
MongoDB
 
MongoDB basics & Introduction
Jerwin Roy
 
Mongodb
Thiago Veiga
 
Philadelphia MongoDB User Group - Your First MongoDB Application
Michael Lynn
 
Ad

More from Scott Hernandez (12)

PPTX
MongoDB 2.8 Replication Internals: Fitting it all together
Scott Hernandez
 
PDF
Advanced Replication Internals
Scott Hernandez
 
PPTX
Realtime Analytics with MongoDB Counters (mongonyc 2012)
Scott Hernandez
 
PDF
MongoDB Operational Best Practices (mongosf2012)
Scott Hernandez
 
PDF
MongoDB Datacenter Awareness (mongosf2012)
Scott Hernandez
 
PPTX
Mongo sf easy java persistence
Scott Hernandez
 
PPTX
MongoDB: Easy Java Persistence with Morphia
Scott Hernandez
 
PPTX
MongoDB: Backup, Restore, and DR
Scott Hernandez
 
PPTX
What's new in the MongoDB Java Driver (2.5)?
Scott Hernandez
 
PPTX
MongoDB Aug2010 SF Meetup
Scott Hernandez
 
PPTX
MongoDB: tips, trick and hacks
Scott Hernandez
 
PPTX
Java Development with MongoDB
Scott Hernandez
 
MongoDB 2.8 Replication Internals: Fitting it all together
Scott Hernandez
 
Advanced Replication Internals
Scott Hernandez
 
Realtime Analytics with MongoDB Counters (mongonyc 2012)
Scott Hernandez
 
MongoDB Operational Best Practices (mongosf2012)
Scott Hernandez
 
MongoDB Datacenter Awareness (mongosf2012)
Scott Hernandez
 
Mongo sf easy java persistence
Scott Hernandez
 
MongoDB: Easy Java Persistence with Morphia
Scott Hernandez
 
MongoDB: Backup, Restore, and DR
Scott Hernandez
 
What's new in the MongoDB Java Driver (2.5)?
Scott Hernandez
 
MongoDB Aug2010 SF Meetup
Scott Hernandez
 
MongoDB: tips, trick and hacks
Scott Hernandez
 
Java Development with MongoDB
Scott Hernandez
 
Ad

Recently uploaded (20)

PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 

MongoDB: Mastering the shell