MongoDB Shell: A Primer

Similar documents
Percona Live Santa Clara, California April 24th 27th, 2017

MongoDB Security: Making Things Secure by Default

ITG Software Engineering

MySQL High Availability

MySQL In the Cloud. Migration, Best Practices, High Availability, Scaling. Peter Zaitsev CEO Los Angeles MySQL Meetup June 12 th, 2017.

Using Percona Monitoring and Management to Troubleshoot MySQL Performance Issues

What s New in MySQL and MongoDB Ecosystem Year 2017

Choosing a MySQL High Availability Solution. Marcos Albe, Percona Inc. Live Webinar June 2017

MongoDB Distributed Write and Read

Database Backup and Recovery Best Practices. Manjot Singh, Data & Infrastrustructure Architect

MongoDB Backup & Recovery Field Guide

How to Scale MongoDB. Apr

Scaling MongoDB. Percona Webinar - Wed October 18th 11:00 AM PDT Adamo Tonete MongoDB Senior Service Technical Service Engineer.

A Support Engineer Walkthrough on ptstalk

What s new in Mongo 4.0. Vinicius Grippa Percona

The course modules of MongoDB developer and administrator online certification training:

Group-B Assignment No. 15

Plug-in Configuration

Course Content MongoDB

MONGODB INTERVIEW QUESTIONS

VMWARE VREALIZE OPERATIONS MANAGEMENT PACK FOR. MongoDB. User Guide

MongoDB Index Types How, when and where should they be used?

MyRocks Engineering Features and Enhancements. Manuel Ung Facebook, Inc. Dublin, Ireland Sept th, 2017

MongoDB: Replica Sets and Sharded Cluster. Monday, November 5, :30 AM - 5:00 PM - Bull

Exploring the replication in MongoDB. Date: Oct

Your First MongoDB Environment: What You Should Know Before Choosing MongoDB as Your Database

Beyond Relational Databases: MongoDB, Redis & ClickHouse. Marcos Albe - Principal Support Percona

CSE 544 Principles of Database Management Systems. Magdalena Balazinska Winter 2015 Lecture 14 NoSQL

Run your own Open source. (MMS) to avoid vendor lock-in. David Murphy MongoDB Practice Manager, Percona

Reduce MongoDB Data Size. Steven Wang

Why Choose Percona Server for MongoDB? Tyler Duzan

Scaling with mongodb

MongoDB Schema Design

A Brief Introduction of TiDB. Dongxu (Edward) Huang CTO, PingCAP

API Gateway 8.0 Multi-Regional Deployment

WiredTiger In-Memory vs WiredTiger B-Tree. October, 5, 2016 Mövenpick Hotel Amsterdam Sveta Smirnova

Brad Dayley. Sams Teach Yourself. NoSQL with MongoDB. SAMS 800 East 96th Street, Indianapolis, Indiana, USA

Document Object Storage with MongoDB

MongoDB Revs You Up: What Storage Engine is Right for You?

MongoDB and Mysql: Which one is a better fit for me? Room 204-2:20PM-3:10PM

Mike Kania Truss

MMS Backup Manual Release 1.4

Advanced Database Project: Document Stores and MongoDB

Why Do Developers Prefer MongoDB?

MongoDB CRUD Operations

MongoDB CRUD Operations

Breaking Barriers: MongoDB Design Patterns. Nikolaos Vyzas & Christos Soulios

MongoDB Monitoring and Performance for The Savvy DBA

Open Source Database Performance Optimization and Monitoring with PMM. Fernando Laudares, Vinicius Grippa, Michael Coburn Percona

Percona Live Updated Sharding Guidelines in MongoDB 3.x with Storage Engine Considerations. Kimberly Wilkins

MongoDB Architecture

MongoDB. David Murphy MongoDB Practice Manager, Percona

MongoDB. Nicolas Travers Conservatoire National des Arts et Métiers. MongoDB

MongoDB Backup and Recovery Field Guide. Tim Vaillancourt Sr Technical Operations Architect, Percona

Running MongoDB in Production, Part I

MongoDB Security Checklist

Scaling MongoDB: Avoiding Common Pitfalls. Jon Tobin Senior Systems

Plug-in Configuration

MongoTor Documentation

Become a MongoDB Replica Set Expert in Under 5 Minutes:

How to upgrade MongoDB without downtime

SQL, NoSQL, MongoDB. CSE-291 (Cloud Computing) Fall 2016 Gregory Kesden

NOSQL EGCO321 DATABASE SYSTEMS KANAT POOLSAWASD DEPARTMENT OF COMPUTER ENGINEERING MAHIDOL UNIVERSITY

MongoDB Shootout: MongoDB Atlas, Azure Cosmos DB and Doing It Yourself

Percona Live September 21-23, 2015 Mövenpick Hotel Amsterdam

Download Studio 3T from

Scaling Without Sharding. Baron Schwartz Percona Inc Surge 2010

POLARDB for MyRocks Extending shared storage to MyRocks. Zhang, Yuan Alibaba Cloud Apr, 2018

Simba ODBC Driver with SQL Connector for MongoDB

User Manual Mail Merge

~3333 write ops/s ms response

Mysql Workbench Doesn't Show

CSE 124: Networked Services Lecture-16

How do we build TiDB. a Distributed, Consistent, Scalable, SQL Database

Distributed Filesystem

Introduction to Database Services

CLOUD-SCALE FILE SYSTEMS

MyRocks deployment at Facebook and Roadmaps. Yoshinori Matsunobu Production Engineer / MySQL Tech Lead, Facebook Feb/2018, #FOSDEM #mysqldevroom

MySQL Replication. Rick Golba and Stephane Combaudon April 15, 2015

MongoDB Tutorial for Beginners

Bringing code to the data: from MySQL to RocksDB for high volume searches

/ Cloud Computing. Recitation 7 October 10, 2017

MongoDB Schema Design for. David Murphy MongoDB Practice Manager - Percona

Copyright 2013, Oracle and/or its affiliates. All rights reserved.

CDP Data Center Console User Guide CDP Data Center Console User Guide Version

Download Studio 3T from

TangeloHub Documentation

MongoDB An Overview. 21-Oct Socrates

Cloud Computing and Hadoop Distributed File System. UCSB CS170, Spring 2018

Group13: Siddhant Deshmukh, Sudeep Rege, Sharmila Prakash, Dhanusha Varik

Google File System, Replication. Amin Vahdat CSE 123b May 23, 2006

Managing CPS Interfaces And APIs

Shen PingCAP 2017

Supplemental Offer and Acceptance Program (SOAP ): Monitoring a Preference List

NPTEL Course Jan K. Gopinath Indian Institute of Science

ElasticSearch in Production

Import, Export, Index MongoDB

CSC Web Programming. Introduction to SQL

MSc, Computer & Systems TalTech. Writes on 2ndQuadrant blog From Turkey Lives in

NoSQL systems: sharding, replication and consistency. Riccardo Torlone Università Roma Tre

Transcription:

MongoDB Shell: A Primer A brief guide to features of the MongoDB shell Rick Golba Percona Solutions Engineer June 8, 2017 1

Agenda Basics of the Shell Limit and Skip Sorting Aggregation Pipeline Explain Plans Write Concern Validation Options Read Preference 2

The MongoDB Shell JavaScript interface to MongoDB Part of the standard installation of MongoDB Used to query and update data, and perform administrative operations Stored by default in /usr/bin Either access the shell from /usr/bin or add the path to the PATH variable $ PATH=$PATH:/usr/bin 3

Common MongoDB Shell Options --port <port> - allows you to specify the port where mongod or mongos is listening; 27017 by default --host <hostname> - allows you to specify the host where mongod or mongos is running; needed when accessing a remote host --username <username> - allows you to specify the username to authenticate if the MongoDB database uses authentication --password <password> - allows you to specify the password for the provided username. If omitted, the shell prompts for the password. --help - provides information on all of the shell options for MongoDB 4

MongoDB Limit and Skip You can limit the number of documents returned by a query > db.<collection>.find().limit(number) For queries that would return a large number of documents, but only a sample set is needed You can also skip a specified number of documents returned by a query > db.<collection>.find().limit(number).skip(number) If a value for limit is not specified, all documents will be initially returned, and then the specified number of documents are skipped 5

MongoDB Sorting MongoDB queries do not returned data in a sorted order unless specified > db.<collection>.find().sort({<key1>:1,<key2>:1...}) 1 specifies an ascending sort, which is the default -1 specifies a descending sort Be careful of multiple sort levels slowing down the query process Queries can be sped up through proper indexing 6

MongoDB Aggregation Pipeline > db.orders.aggregate([ {$match: {status: "active"}}, {$group: {_id: "$cust_id":, total: {$sum: "$amount"}}} ] ) 7

MongoDB Aggregation Pipeline - $match > db.orders.aggregate([ {$match: {status: "active"}}, {$group: {_id: "$cust_id":, total: {$sum: "$amount"}}} ] ) 8

MongoDB Aggregation Pipeline - $group > db.orders.aggregate([ {$match: {status: "active"}}, {$group: {_id: "$cust_id":, total: {$sum: "$amount"}}} ] ) 9

MongoDB Explain Plan > db.<collection>.explain().<method> Returns information on the query plan for aggregate() count() distinct() find() group() remove() update() Optional <method> allows you to control verbosity of the plan 10

MongoDB Explain Plan Inclusions > db.orders.explain().aggregate([ {$match: {status:"active"}}, {$group: {_id:"$ cust_id",total: {$sum:"$amount"}}}]) Passes information through a series of stages to completion COLLSCAN for collection scan (all documents) IXSCAN for scan of index keys (subset of documents) FETCH for retrieval of data SHARD_MERGE for merging results from multiple shards Shows information on rejected plans, if available 11

MongoDB Write Concern By default, MongoDB only requires write acknowledgement from the master in a replica set You can override this and specify the number of replicas that must acknowledge prior to the write being processed to the database This can either be a specified number of nodes or a majority of nodes To specify write concern 2 on an insert > db.movies.insert( { title: "Logan", year : 2017, director: "James Mangold" }, { writeconcern: { w: 2 } }) Use {writeconcern: {w: "majority"}} for majority option 12

Write Concern Examples Write Concern 1 Write Concern 2 (or majority) 13

validate Command Checks the structures within a namespace for correctness by scanning the collection s data and indexes Returns information regarding the on-disk representation of the collection Can be slow, particularly on larger data sets While running, it holds an exclusive lock on the collection This blocks all reads and writes until the validate command finishes Output differs based on storage engine > db.collection.validate(<true>) true specifies a complete validation and will require more time 14

validate Output Summary validate.ns - full namespace name of the collection validate.nrecords - number of documents in the collection validate.nindexes - number of indexes on the collection validate.keysperindex - number of keys in each index validate.valid - returns true if all aspects of the collection are valid validate.errors - if valid returns false, this field contains a message describing the validation error validate.ok - displays 1 for successful completion of command, 0 if it fails 15

MongoDB Read Preference By default, an application sends its read requests to the primary member of a replica set You can direct the read request to another member of the replica set This may return stale data due to write concerns and asynchronous replication Setting read preference mode is specific to the driver being used 16

MongoDB Read Preference Options primary - default, operations read from the current replica set primary primarypreferred - operations read from the primary but if it is unavailable, operations can read from secondary members secondary - operations read from the secondary members of the replica set secondarypreferred - operations read from secondary members but if no secondary members are available, operations read from the primary nearest - operations read from member of the replica set with the least network latency regardless of type maxstalenessseconds can be specified for all but primary to determine a time threshold after which the member is not used for reads. Must be >90. 17

Percona Live Europe Call for Papers & Registration are Open! Championing Open Source Databases MySQL, MongoDB, Open Source Databases Time Series Databases, PostgreSQL, RocksDB Developers, Business/Case Studies, Operations September 25-27th, 2017 Radisson Blu Royal Hotel, Dublin, Ireland Submit Your Proposal by July 17 th! www.percona.com/live/e17 18

DATABASE PERFORMANCE Database Performance Matters MATTERS