A B C D E F G H I J K L M N O P Q R S T U V W

Symbols

[top]

!== (both value and type are not equal) operator, 42

!= (is not equal) operator, 42

! (not) operator, 42

$add operator, 175

$addToSet operator, 147, 173

$all operator, 110

$and operator, 110

$avg operator, 173

$bit operator, 147

$concat operator, 175

$divide operator, 175

$each operator, 147

$elemMatch operator, 110

$exists operator, 110

$first operator, 173

$group operator, 172, 287

$gte operator, 110

$gt operator, 110

$inc operator, 147

$in operator, 110

$last operator, 173

$limit operator, 172, 287

$lte operator, 110

$lt operator, 110

$match operator, 172

$max operator, 173

$min operator, 173

$mod operator, 110, 175

$multiply operator, 175

$ne operator, 110

$nin operator, 110

$nor operator, 110

$not operator, 110

$ operator, 147

$or operator, 110

$pop operator, 147

$project operator, 172

$pullAll operator, 147

$pull operator, 147

$push operator, 147, 173

$regex operator, 110

$rename operator, 147

$setOnInsert operator, 147

$set operator, 147

$size operator, 110

$skip operator, 172

$slice operator, 147

$sort operator, 147, 172

$strcasecmp operator, 175

$substr operator, 175

$subtract operator, 175

$sum operator, 173

$toLower operator, 175

$toUpper operator, 175

$type operator, 110

$unset operator, 147

$unwind operator, 172

% (modulous) operator, 40

&& (and) operator, 42

* (multiplication) operator, 40

+ (addition) operator, 40

++ (increment) operator, 40

‑‑ (decrement) operator, 40

‑ (subtraction) operator, 40

/ (brackets), 45, 49

/ (division) operator, 40

() (parentheses), 50

< (is less than) operator, 42

<= (is less than or equal to) operator, 42

=== (both value and type are equal) operator, 42

== (is equal to) operator, 42

> (is greater than) operator, 42

>= (is greater than or equal to) operator, 42

|| (or) operator, 42

A

[top]

accessing

access control, configuring, 7882

documents, counting, 125127

GridFS Stores, 484

files, 492493

Node.js applications, 498, 500501

Python, 494, 496497

HTTP interfaces, 26

Java applications, 209

applying aggregation, 225228

finding distinct field values, 218221

grouping results, 221225

limiting result sets, 209218

MongoDB shell clients, 2731

MongoGridFS objects in PHP, 490

Node.js applications, 391

applying aggregation, 406409

limiting result sets, 391399

objects, 12

PHP applications, 273

applying aggregation, 287290

grouping results, 283287

limiting result sets, 273281

searching distinct field values, 281283

Python application, 331

applying aggregation, 344347

grouping results, 341

limiting result sets, 331338

accounts

authentication, starting, 79

database administrator, formatting, 79

users

administrator, formatting, 78

formatting, 72

managing, 7078

accuracy, 7, 17

ACID (Atomic, Consistency, Isolation, Durability), 7

adding

documents

collections, 149151, 232

Java applications, 231235

Node.js applications, 411416

PHP applications, 293297

Python application, 349353

error handling, 6567

files, GridFS Stores, 485, 491, 494, 498

indexes, 438440

items to arrays, 63

objects, 12

shards to clusters, 473

addition (+) operator, 40

addUser() method, 70, 87, 187, 370

add_user() method, 313

admin database

access control, configuring, 7882

overview of, 69

user accounts, managing, 7078

aggregate() method, 89, 172, 188, 225, 254, 314, 345, 371

aggregation

applying, 171178

Java, 225228

Node.js applications, 406409

operators

expression, 173175

framework, 174172

PHP applications, 287290

pipelines, 176

Python application, 344347

analyzing queries, 449451

and (&&) operator, 42

anonymous functions, 51

append() method, 192

applications

Java. See Java applications

Node.js. See Node.js applications

PHP. See PHP applications

Python. See Python applications

applying

aggregation, 171178

Java, 225228

Node.js applications, 406409

PHP applications, 287290

pipelines, 176

Python application, 344347

anonymous functions, 51

arrays, 6065

if statements, 4344

indexes, 438443

replication, 459467

results, mapReduce() method, 178183

arbiter servers, 460

arithmetic operators, 4041

Array objects, PHP applications, 257

arrays, 39

applying, 6065

combining, 62

fields

contents, 118

searching documents based on, 118

items

adding/deleting, 63

searching, 63

iterating through, 62

manipulating, 61

strings

converting, 62

splitting, 58

values, searching documents based on, 117

assigning

roles, 71

values to variables, 38

assignment operators, 41

Atomic, Consistency, Isolation, Durability. See ACID

atomic write operations, 15

authenticate() method, 187, 253, 313, 370

authentication, starting, 79

auth() method, 87

auth setting, 24

B

[top]

background property, 440

backing up

databases, 454455

MongoDB, 454455

BasicDBObject object, Java applications, 191194

batchInsert() method, 254, 294

batchSize() method, 108, 188, 256, 373

batch_size() method, 316

binary JSON. See BSON

bind_ip setting, 24

blocks

finally, 66

try/catch, 65

Booleans, 39

both value and type are equal (===) operator, 42

both value and type are not equal (!==) operator, 42

brackets (/), 45, 49

BSON (binary JSON), 9

C

[top]

callback functions, 368

capped collections, formatting, 1415, 436437

changeUserPassword() method, 87

characters, null, 9

clients, shells

accessing MongoDB from, 2731

scripting, 3334

cloneCollection() method, 87

cloneDatabase() method, 87

close() method, 186, 191, 252, 312, 368

clusterAdmin role, 71

privileges, 91

clusters, sharding

adding, 473

deploying, 472

formatting, 475479

code property, 145

collection_names() method, 313

Collection object, 89

Node.js applications, 370371

Python application, 313

collections, 9

capped, formatting, 1415, 436437

databases, managing, 433437

deleting, 98100

design, 16

documents. See also documents

adding, 149151, 232

configuring write concerns, 143144

database update operators, 146147

deleting, 161163, 236

error handling, 144

manipulating, 143

paging, 136

PHP applications, 294

retrieving, 112116

saving, 155158, 239

status of database write requests, 145

updating, 151155, 243

upserting, 158160, 246

formatting, 9698

lists, viewing, 96

managing, 96

reindexing, 441443

renaming, 435436

sharding, enabling, 474

statistics, viewing, 443444

users, counting documents, 126

collections() method, 370

column store databases, 7

combining

arrays, 62

strings, 58

command‑line parameters, 22-23

commands

<database>, 87

getLastError, 144-145

mongofiles, 482483

parameters, 3031

shells, 28, 3233

top, 451453

use <new_database_name>, 92

comparison operators, 42

compound indexes, 439

cond parameter, 168

config servers, 470, 472

configuring

access control, 7882

databases, 22

error handling, 144

MongoDB, 2326

PHP application write concerns, 257

servers, 461

sharding tag ranges, 475

write concerns, 143144

connect() method, 186, 252, 368

Connection objects, overview of, 86

connectionId property, 145

connections

databases, configuring error handling, 144

write concerns, configuring, 143144

consoles, starting shells, 28

constructors, shells, 29

contents, searching, 118

converting

arrays into strings, 62

records, 9

copy() method, 191

copyDatabase() method, 87

copying databases, 434435

copyTo() method, 89

count() method, 89, 108, 126, 188, 202, 254, 256, 265, 314, 316, 324, 371, 373, 383

counting documents, 125127

Java applications, 201203

Node.js applications, 383385

PHP applications, 265267

Python application, 324326

countWords() method, 202

create_collection() method, 313

createCollection() method, 87, 97, 187, 253, 370

createIndex() method, 89

current() method, 256

Cursor objects, 107108

documents, counting, 126

Node.js applications, 373

Python applications, 315, 324, 327, 332

results

limiting, 130138

sorting, 128130

customizing objects, defining, 5455

D

[top]

data life cycles, 17

data types

JavaScript, 3839

MongoDB, 1011

<database> command, 87

Database object, 8687

Node.js applications, 369370

Python applications, 313

database_names() method, 312

databases

access control, implementing, 80

admin, overview of, 69

administrator accounts, formatting, 79

backing up, 454455

Collection object, 89

collections, managing, 433437

column store, 7

configuring, 22

Connection objects, overview of, 86

connections, configuring error handling, 144

copying, 434435

deleting, 9394

document store, 6

formatting, 9293

graph store, 7

indexes, 438443

key‑value, 6

lists, viewing, 91

managing, 91

optimizing, 443453

repairing, 453454

modifying, 92

profiling, 446448

queries, evaluating, 449451

results

grouping, 167171

limiting, 130138

sorting, 128130

roles, assigning, 71

selecting, 78

sharding, enabling, 474

shells, managing, 433

statistics, viewing, 9496, 443444

testing, 31

top command, 451453

update operators, 146147

users, listing, 74

validating, 444446

write concerns, configuring, 143144

dataset examples, implementing, 100103

dataSize() method, 89

DB object

Java applications, 187

PHP applications, 253

db() method, 368

dbAdminAnyDatabase role, 71

dbAdmin role, 71

DBCollection object

Java applications, 188

PHP applications, 279

DBCursor object, Java applications, 189191, 202, 204, 210, 213

DBObject objects, 191194

declaring variables, 38

decrement (‑‑) operator, 40

default_id indexes, 439

defining

documents, 13

functions, 49

objects, customizing, 5455

variables, 3738

deleting

collections, 98100

databases, 9394

documents

collections, 236

Java applications, 236238

Node.js applications, 416419

PHP applications, 297299

Python application, 353355

files, GridFS Stores, 486, 491, 495, 499

indexes, 441

items from arrays, 63

objects, 12

users, 77

denormalizing data, 1314

deploying

replica sets, 462463

sharding clusters, 472

design, 6, 16

diagnostics, managing databases, 443453

Dictionary objects, PHP applications, 317

displayGroup() method, 284

displayWords() method, 131

distinct field values

Node.js applications, 400402

PHP applications, 281283

Python applications, 339341

searching, 138140, 218221

distinct() method, 138, 188, 254, 314, 316, 339, 371

distinctField() method, 89

division (/) operator, 40

document store databases, 6

documents

collections, 9. See also collections

adding, 149151, 232

configuring write concerns, 143144

database update operators, 146147

deleting, 161163, 236

error handling, 144

retrieving, 112116

saving, 155158, 239

status of database write requests, 145

updating, 151155, 243

upserting, 158160, 246

counting, 125127

Cursor objects, 107108

distinct field values, retrieving, 139

embedding, denormalizing data, 1314

Java applications

adding, 231235

counting, 201203

deleting, 236238

saving, 239241

searching, 194201

sorting results, 203206

updating, 241245

upserting, 245249

manipulating, 143

Node.js applications, 411

adding, 411416

counting, 383385

deleting, 416419

grouping results, 402406

objects used as, 374

paging, 397

retrieving, 377383

saving, 419423

searching distinct field values, 400402

sorting results, 385388

updating, 423427

upserting, 427431

overview of, 910

parameters, PHP Arrays objects as, 257

PHP applications, 293

adding, 293297

counting, 265267

deleting, 297299

reviewing, 260262

saving, 299302

searching, 259265

sorting results, 267270

updating, 302305

upserting, 305308

Python application, 349

adding, 349353

counting, 324326

deleting, 353355

saving, 355357

searching, 318324

sorting results, 326328

updating, 358361

upserting, 361364

references, normalizing data, 1213

results

limiting, 130138

sorting, 128130

shells, searching in, 112116

sizing, 10

specific, retrieving (using PHP), 262265

specific sets of, searching, 117122

updating, 15

values, searching, 118

do/while loops, 45

drivers

Java applications, 185194

Node.js applications, 367377

PHP applications, 251259

drop() method, 89, 188, 254, 314, 371

drop_collection() method, 313

drop_database() method, 312

drop_index() method, 314

dropCollection() method, 370

dropDatabase() method, 87, 93, 186-187

dropDups property, 440

dropIndex() method, 89, 188, 254

E

[top]

embedding documents, denormalizing data, 1314

enabling sharding

collections, 474

databases, 474

engines, starting/stopping, 22

ensureIndex() method, 89, 188, 254, 314

err property, 145

errors

handling

adding, 6567

document collections, 144

throwing, 66

escape codes, string objects, 56

‑‑eval command‑line option, 3132

eval() method, 87

evaluating

queries, 449451

shells, expressions, 3132

example datasets, implementing, 100103

executing

shell scripting, 32

variables, 38

exit command, 28

expression operators, aggregation, 173175

expressions, evaluating shells, 3132

F

[top]

fault tolerance, 462

fields

addUser() method, 70

arrays

contents, 118

searching documents based on, 118

limiting, 132, 212

naming, 9

Node.js applications, 394

parameters, 213

PHP applications, limiting, 276

Python applications, limiting, 334

values

searching, 117, 138140, 218221

fields:value operator, 110

files

configuration settings, 24

GridFS Stores

adding, 485, 491, 494, 498

deleting, 486, 491, 495, 499

listing, 485

manipulating, 492493

retrieving, 486, 491, 495, 499

JavaScript, specifying, 3233

finalize option, 179

finalize parameter, 168

finally blocks, 66

find operations

PHP applications, 283287

find() method, 89, 107, 112, 126, 188, 254, 259, 314, 371, 377

fields, limiting, 132

find_and_modify() method, 314

find_one() method, 314

findAndModify() method, 89, 188, 254, 371

finding. See searching

findOne() method, 89, 188, 194, 254, 259, 371

findone() method, 112

results, grouping, 167171, 221225

for loops, 4546

for/in loops, 4647

forEach() method, 108

formatting. See also design

capped collections, 1415, 436437

collections, 9698

config servers, instances, 472

database administrator accounts, 79

databases, 9293

example datasets, 101

functions, 4952

replica sets, 463467

sharding clusters, 475479

users

accounts, 72

administrator accounts, 78

frameworks, aggregation operators, 174172

fromdb parameter, 434

fromhost parameter, 434

functions

anonymous, applying, 51

callback, 368

defining, 49

formatting, 4952

greeting(), 50

print(), 32

values, returning, 50

variables, passing, 50

G

[top]

generating new data results, 178183

geospatial indexes, 439

getCollection() method, 87, 187

getCollectionNames() method, 96

getConnections() method, 252

getDatabaseNames() method, 186

getDB() method, 86, 186

getIndexes() method, 89

getLastError command, 144-145

getLastError() method, 187

getMongo() method, 87

getName() method, 87

getNext() method, 256

getReadPrefMode() method, 86

getReadPrefTagSet() method, 86

getSiblingDB() method, 87

getStats() method, 188

graph store databases, 7

greeting() function, 50

GridFS Stores

files

adding, 485, 491, 494, 498

deleting, 486, 491, 495, 499

manipulating, 492493

retrieving, 486, 491, 495, 499

implementing, 481

Java, 484489

Node.js applications

accessing, 498, 500501

implementing, 497501

overview of, 481482

PHP, 489493

Python

accessing, 496497

implementing, 494497

shells, implementing, 482484

group() method, 89, 168, 188, 254, 314, 371

grouping

objects, 169, 284

results, 167171, 221225

Node.js applications, 402406

PHP applications, 283287

Python applications, 341

growth, documents, 15. See also updating

H

[top]

handling errors, 6567

hashed indexes, 439

hasNext() method, 108, 191, 256

Hello World, 49

help <option> command, 28

help() method, 87

high availability, replication, 460

hint() method, 108

horizontal scaling, 6

hostInfo() method, 87

HTTP interfaces, accessing, 26

I

[top]

if statements, applying, 4344

implementing, 6

access control, 80

example datasets, 100103

GridFS Stores, 481

Java, 484489

Node.js applications, 497501

PHP, 489493

Python, 494497

shells, 482484

in Java applications, 185. See also Java applications

looping, 4449

replication, 459

sharding, 459, 468479

strategies, 7

switch statements, 44

upsert, 158

increment (++) operator, 40

indexes, 16

adding, 438440

collections, reindexing, 441443

deleting, 441

indexOf() method, 58

initial parameter, 168

insert() method, 89, 158, 188, 231, 254, 314, 371

inserting, 149. See also adding

installing MongoDB, 22

instances, formatting config servers, 472

interfaces

HTTP, 26

REST, 26

interrupting loops, 47

is equal to (==) operator, 42

is greater than (>) operator, 42

is greater than or equal to (>=) operator, 42

is less than (<) operator, 42

is less than or equal to (<=) operator, 42

is not equal (!=) operator, 42

isAuthenticated() method, 187

isCapped() method, 89

items, arrays

adding/deleting, 63

searching, 63

iterating through arrays, 62

iterator() method, 191

J

[top]

Java applications, 185

BasicDBObject object, 191194

data access, 209

applying aggregation, 225228

finding distinct field values, 218221

grouping results, 221225

limiting result sets, 209218

DB object, 187

DBCollection object, 188

DBCursor object, 202, 204, 210

DBObject objects, 191194

documents

adding, 231235

counting, 201203

deleting, 236238

saving, 239241

searching, 194201

sorting results, 203206

updating, 241245

upserting, 245249

driver objects, 185194

GridFS Stores, implementing, 484489

MongoClient object, 186

results, paging, 215

JavaScript

arrays, applying, 6065

data types, 3839

error handling, adding, 6567

files, specifying, 3233

functions, formatting, 4952

looping, implementing, 4449

objects, 5356

operators, 4044. See also operators

shells, 30, 40

strings, manipulating, 5660

variables

defining, 3738

scope, 5253

journal setting, 24

jsMode option, 179

K

[top]

key‑value databases, 6

keyf parameter, 168

keys

parameters, 168, 434

sharding, selecting, 470471

values

grouping objects, 169, 284

keywords

function, 49

return, 50

var, 38

L

[top]

lastOp property, 145

life cycles, data, 17

limiting

fields, 132, 212

Node.js applications, 394

PHP applications, 276

Python applications, 334

result sets, 130138, 209218

results

Node.js applications, 391399

PHP applications, 273281

Python application, 331338

limit option, 179

limit() method, 108, 130, 136, 191, 210, 216, 256, 274, 316, 332, 373

limitResults() method, 210

listCollections() method, 253

listDBs() method, 252

listing files, GridFS Stores

Java, 485

Node.js applications, 498

PHP, 490491

Python, 494

lists

collections, viewing, 96

databases, viewing, 91

users, 74

literals, objects, 39

load() method, 32

log [name] : command, 28

logappend setting, 24

logout() method, 87

logpath setting, 24

lookups, denormalized documents, 13

looping

do/while loops, 45

for loops, 4546

for/in loops, 4647

implementing, 4449

interrupting, 47

variables, 38

while loops, 45

M

[top]

main() method, 202

managing

access control, configuring, 7882

collections, 96

configuration settings, 23

databases, 91

collections, 433437

indexes, 438443

optimizing, 443453

repairing, 453454

shells, 433

user accounts, 7078

manipulating. See also modifying

arrays, 61

documents, 143

GridFS Stores

files, 492493

Node.js applications, 500501

Python, 496497

requests, applying aggregation, 171178

results, 181

strings, 5660

map() method, 108, 131

mapReduce() method, 89, 188

results, applying, 178183

max() method, 108

maxConns setting, 24

methods

add_user(), 313

addUser(), 70, 87, 187, 370

aggregate(), 89, 172, 188, 225, 254, 314, 345, 371

append(), 192

auth(), 87

authenticate(), 187, 253, 313, 370

batch_size(), 316

batchInsert(), 254, 294

batchSize(), 108, 188, 256, 373

changeUserPassword(), 87

cloneCollection(), 87

cloneDatabase(), 87

close(), 186, 191, 252, 312, 368

Collection objects, 89

collection_names(), 313

collections(), 370

connect(), 186, 252, 368

Connection objects, 86

copy(), 191

copyDatabase(), 87

copyTo(), 89

count(), 89, 108, 126, 188, 202, 254, 256, 265, 314, 316, 324, 371, 373, 383

countWords(), 202

create_collection(), 313

createCollection(), 87, 97, 187, 253, 370

createIndex(), 89

current(), 256

Cursor object, 108

Database objects, 87

database_names(), 312

dataSize(), 89

DB objects, 187

db(), 368

DBCollection objects, 188

DBCurosor objects, 191

displayGroup(), 284

displayWords(), 131

distinct(), 138, 188, 254, 314, 316, 339, 371

distinctField(), 89

drop(), 89, 188, 254, 314, 371

drop_collection(), 313

drop_database(), 312

drop_index(), 314

dropCollection(), 370

dropDatabase(), 87, 93, 186-187

dropIndex(), 89, 188, 254

ensureIndex(), 89, 188, 254, 314

eval(), 87

find(), 89, 107, 112, 126, 188, 254, 259, 314, 371, 377

find_and_modify(), 314

find_one(), 314

findAndModify(), 89, 188, 254, 371

findOne(), 89, 188, 194, 254, 259, 371

findone(), 112

forEach(), 108

getCollection(), 87, 187

getCollectionNames(), 96

getConnections(), 252

getDatabaseNames(), 186

getDB(), 86, 186

getIndexes(), 89

getLastError(), 187

getMongo(), 87

getName(), 87

getNext(), 256

getReadPrefMode(), 86

getReadPrefTagSet(), 86

getSiblingDB(), 87

getStats(), 188

group(), 89, 168, 188, 254, 314, 371

hasNext(), 108, 191, 256

help(), 87

hint(), 108

hostInfo(), 87

indexOf(), 58

insert(), 89, 158, 188, 231, 254, 314, 371

isAuthenticated(), 187

isCapped(), 89

iterator(), 191

limit(), 108, 130, 136, 191, 210, 216, 256, 274, 316, 332, 373

limitResults(), 210

listCollections(), 253

listDBs(), 252

load(), 32

logout(), 87

main(), 202

map(), 108, 131

mapReduce(), 89, 178183, 188

max(), 108

min(), 108

MongoClient object, 186, 252

native, shells, 29

new Mongo (), 86

next(), 108, 115, 256

objsLeftInBatch(), 108

open(), 368

partitions, selecting, 471472

print(), 40

printjson(), 40

push(), 60

read_preference(), 312-314

readPref(), 108

reIndex(), 89

remove(), 89, 161, 188, 236, 254, 297, 314, 371

remove_user(), 313

removeUser(), 87, 187, 370

rename(), 314, 371

renameCollection(), 89

repairDatabase(), 87

resetDoc(), 242

runCommand(), 87, 144

save(), 89, 155, 188, 239, 254, 299, 314, 371

selectCollection(), 252-253

selectDB(), 252

serverStatus(), 87

setReadPreference(), 186-188, 252-254, 313

setReadPrefMode(), 86

setSlaveOk(), 86

setWriteConcern(), 186-188

showWord(), 300

shutdownServer(), 87

size(), 108, 191

skip(), 108, 136, 191, 216, 256, 316, 373

snapshot(), 108

sort(), 108, 128, 191, 204, 256, 267, 316, 326, 373, 386

split(), 58

stats(), 89, 95

storageSize(), 89

String object, manipulating, 56

toArray(), 108, 191, 373

totalIndexSize(), 89

totalSize(), 89

update(), 89, 188, 242, 254, 302, 305, 314, 371

validate(), 92

version(), 87

write_concern(), 312-314

min() method, 108

models, planning, 1117

modifying

databases, 92

objects, 12

modulous (%) operator, 40

MongoClient object

Java applications, 186

Node.js applications, 368

PHP applications, 252

Python applications, 312

MongoCollection object, PHP applications, 253254

MongoCursor object, PHP applications, 256, 274-276

MongoDB. See also databases

backing up, 454455

configuring, 2326

data types, 1011

HTTP interfaces, accessing, 26

installing, 22

Java applications. See Java applications

overview of, 810

shells

accessing clients, 2731

scripting, 3134

starting, 22

stopping, 25

MongoDB object, PHP applications, 253

mongofiles command, 482483

MongoGridFS objects in PHP, accessing, 490

multikey indexes, 439

multiple documents, searching, 115. See also documents

multiplication (*) operator, 40

N

[top]

n property, 145

name property, 440

naming

fields, 9

variables, 38

native methods, shells, 29

new Mongo () method, 86

next() method, 108, 115, 256

noauth setting, 24

Node.js applications, 367

Collection object, 370371

Cursor objects, 373

data access, 391

applying aggregation, 406409

grouping results, 402406

limiting result sets, 391399

Database object, 369370

documents, 411

adding, 411416

counting, 383385

deleting, 416419

paging, 397

retrieving, 377383

saving, 419423

searching distinct field values, 400402

sorting results, 385388

updating, 423427

upserting, 427431

driver objects, 367377

GridFS Stores

accessing, 498, 500501

implementing, 497501

MongoClient object, 368

objects used as documents/parameters, 374

specific documents, 380

nohttpinterface setting, 24

normalizing data, 1213

NoSQL

overview of, 6

selecting, 78

not (!) operator, 42

null characters, 9

null variables, 39

number

of replica sets, 462

of servers, 462

numbers, 38

O

[top]

objects, 9. See also documents

arrays, manipulating, 61

BasicDBObject, 191194

Collection, 89

Connection, overview of, 86

Cursor, 107108

counting documents, 126

limiting results, 130138

sorting results, 128130

Database, 8687

DB, 187

DBCollection, 188

DBCursor, 189191, 202, 204, 210

DBObject, 191194

defining, customizing, 5455

drivers

Java applications, 185194

Node.js applications, 367377

PHP applications, 251259

fields, limiting, 132, 212

grouping, 169

JavaScript, 5356

key values, grouping, 284

literals, 39

MongoClient, 186

Node.js applications, used as documents/parameters, 374

patterns, prototyping, 55

planning, 11

strings, escape codes, 56

syntax, 5354

objsLeftInBatch() method, 108

ok property, 145

open() method, 368

operations, atomic write, 15

operator parameter, 287

operators

$, 148

$add, 175

$addToSet, 148, 173

$all, 110

$and, 110

$avg, 173

$bit, 148

$concat, 175

$divide, 175

$each, 148

$elemMatch, 110

$exists, 110

$first, 173

$group, 172, 287

$gt, 110

$gte, 110

$in, 110

$inc, 147

$last, 173

$limit, 172, 287

$lt, 110

$lte, 110

$match, 172

$max, 173

$min, 173

$mod, 110, 175

$multiply, 175

$ne, 110

$nin, 110

$nor, 110

$not, 110

$or, 110

$pop, 148

$project, 172

$pull, 148

$pullAll, 148

$push, 148, 173

$regex, 110

$rename, 147

$set, 148

$setOnInsert, 147

$size, 110

$skip, 172

$slice, 148

$sort, 148, 172

$strcasecmp, 175

$substr, 175

$subtract, 175

$sum, 173

$toLower, 175

$toUpper, 175

$type, 110

$unset, 148

$unwind, 172

addition (+), 40

aggregation

expression, 173175

framework, 174172

and (&&), 42

arithmetic, 4041

assignment, 41

both value and type are equal (===), 42

both value and type are not equal (!==), 42

comparison, 42

decrement (‑‑), 40

division (/), 40

fields:value, 110

increment (++), 40

is equal to (==), 42

is greater than (>), 42

is greater than or equal to (>=), 42

is less than (<), 42

is less than or equal to (<=), 42

is not equal (!=), 42

JavaScript, 4044

modulous (%), 40

multiplication (*), 40

not (!), 42

or (||), 42

query, 109110

subtraction (‑), 40

update, 146147

optimizing databases, 443453

options, ‑‑eval command‑line, 3132

orders, sorting, 128130

or (||) operator, 42

out option, 179

outputting data in shells, 40

P

[top]

paging

documents, Node.js applications, 397

requests, 128

results, 136

Java applications, 215

PHP applications, 278

Python applications, 336

parameters

command‑line, 22, 23

commands, 3031

documents, PHP Arrays objects as, 257

fields, 213

group() method, 168

Node.js applications, objects used as, 374

operator, 287

projection, 133

query, 109, 139, 161

parentheses (()), 50

partitions, selecting methods, 471472

passing variables to functions, 50

patterns, prototyping objects, 55

performance, 17

databases, managing, 443453

models, planning, 1117

replication, 460. See also replication

PHP applications, 251

Array objects, 257

data access, 273

applying aggregation, 287290

grouping results, 283287

limiting result sets, 273281

searching distinct field values, 281283

DB object, 253

DBCollection object, 279

Dictionary objects, 317

documents, 293

adding, 293297

counting, 265267

deleting, 297299

reviewing, 260262

saving, 299302

searching, 259265

sorting results, 267270

updating, 302305

upserting, 305308

driver objects, 251259

fields, limiting, 276

GridFS Stores, implementing, 489493

MongoClient object, 252

MongoCollection object, 253254

MongoCursor object, 256, 274-276

MongoDB object, 253

results, paging, 278

write concerns, configuring, 257

pipelines, applying aggregation, 176

planning models, 1117

port setting, 24

primary servers, 460

print() function, 32

print() method, 40

printjson() method, 40

privileges, clusterAdmin role, 91

profiling databases, 446448

projection parameter, 133

prototyping object patterns, 55

push() method, 60

Python applications, 311

Collection object, 313

Cursor objects, 315, 332

data access, 331

applying aggregation, 344347

grouping results, 341

limiting result sets, 331338

Database object, 313

distinct field values, 339341

documents, 349

adding, 349353

counting, 324326

deleting, 353355

saving, 355357

searching, 318324

sorting results, 326328

updating, 358361

upserting, 361364

fields, limiting, 334

GridFS Stores

accessing, 496497

implementing, 494497

MongoClient object, 312

results, paging, 336

Q

[top]

queries

evaluating, 449451

routers, 469

starting, 473

query operators, 109110

query options, 179

query parameters, 139, 161

R

[top]

RAM (random access memory), 10

random access memory. See RAM

RDBMSs (relational database management systems), 68

read role, 71

read_preference() method, 312-314

readAnyDatabase role, 71

readPref() method, 108

readWrite role, 71

readWriteAnyDatabase role, 71

records, converting, 9

reduce parameter, 168

references, normalizing data, 1213

reIndex() method, 89

reindexing collections, 441443

relational database management systems. See RDBMSs

reliability, 7

remove() method, 89, 161, 188, 236, 254, 297, 314, 371

remove_user() method, 313

removeUser() method, 87, 187, 370

removing. See deleting

rename() method, 314, 371

renameCollection() method, 89

renaming collections, 435436

repairDatabase() method, 87

repairing databases, 453454

replacing words in strings, 58

replica sets. See also replication

deploying, 462463

formatting, 463467

types of, 460

replication, 16, 459

applying, 459467

strategies, applying, 461

requests

manipulating, applying aggregation, 171178

Node.js applications, 374

paging, 128

PHP applications, applying aggregation, 287290

status of database write, retrieving, 145

resetDoc() method, 242

REST interfaces, 26

rest setting, 24

results, 3031

grouping, 167171, 221225

Java applications

paging, 215

sorting, 203206

limiting

Java applications, 209218

PHP applications, 273281

manipulating, 181

mapReduce() method, applying, 178183

Node.js applications

grouping, 402406

limiting, 391399

sorting, 385388

paging, 136

PHP applications

grouping, 283287

paging, 278

sorting, 267270

Python application

limiting, 331338

sorting, 326328

Python applications

grouping, 341

paging, 336

sets, limiting, 130138

sorting, 128130

retrieving

distinct field values, 139, 219, 282, 400

documents

from collections, 112116

Node.js applications, 377383

Python applications, 319

using Java, 195

files, GridFS Stores, 483, 486, 491, 495, 499

specific documents (using PHP), 262265

status of database write requests, 145

return keyword, 50

returning

fields, limiting, 212

objects, 132

values from functions, 50

reviewing documents, PHP applications, 260262

roles

assigning, 71

clusterAdmin privileges, 91

routers

queries, 469

starting, 473

runCommand() method, 87, 144

S

[top]

save() method, 89, 155, 188, 239, 254, 299, 314, 371

saving

databases, 454455

documents

collections, 155158, 239

Java applications, 239241

Node.js applications, 419423

PHP applications, 299302

Python application, 355357

scalability, 6

scope

options, 179

variables, 5253

scripting shells, 3134

clients, 3334

executing, 32

searching

array items, 63

contents, 118

distinct field values, 138140, 218221

Node.js applications, 400402

PHP applications, 281283

documents

in shells, 112116

Java applications, 194201

Node.js applications, 377383

PHP applications, 259265

Python application, 318324

multiple documents, 115

results, grouping, 167171

specific documents, Node.js applications, 380

specific sets of documents, 117122

substrings in strings, 58

secondary servers, 460

selectCollection() method, 252-253

selectDB() method, 252

selecting

NoSQL, 78

partitioning methods, 471472

RDBMS, 78

sharding keys, 470471

servers

replication, 460. See also replication

sharding, types of, 469

serverStatus() method, 87

setReadPreference() method, 186-188, 252,-254, 313

setReadPrefMode() method, 86

sets, results. See also results

Java applications, 203206

limiting, 130138

limiting access in Java applications, 209218

PHP applications, 273281

setSlaveOk() method, 86

setup. See configuring

setWriteConcern() method, 186-188

shard servers, 469

sharding, 16, 459

clusters

adding, 473

deploying, 472

formatting, 475479

collections, enabling, 474

databases, enabling, 474

implementing, 468479

keys, selecting, 470471

servers, types of, 469

tag ranges, configuring, 475

shells

aggregation, applying, 171178

clients

accessing MongoDB from, 2731

scripting, 3334

commands, 28, 3233

constructors, 29

databases, managing, 433

documents

adding to collections, 149151

counting, 125127

deleting, 161163

limiting result sets, 130138

saving, 155158

searching in, 112116

sorting results, 128130

updating, 151155

upserting, 158160

expressions, evaluating, 3132

GridFS Stores, implementing, 482484

JavaScript, 30, 40

native methods, 29

objects, grouping, 222

results

grouping, 167171

mapReduce() method, 178183

scripting, 3134

starting, 28

user accounts, formatting, 72

show <option> command, 28

showWord() method, 300

shutdownServer() method, 87

single field indexes, 439

size() method, 108, 191

sizing

collection design, 16

documents, 10

Node.js application results, limiting, 392394

results, limiting by, 210

skip() method, 108, 136, 191, 216, 256, 316, 373

slaveOk parameter, 434

snapshot() method, 108

sorting results, 128130

Java applications, 203206

Node.js applications, 385388

PHP applications, 267270

Python application, 326328

sort option, 179

sort() method, 108, 128, 191, 204, 256, 267, 316, 326, 373, 386

sparse property, 440

specific documents

Node.js applications, 380

PHP, 262265

Python applications, 321

specific sets of documents, searching, 117122

specifying JavaScript files, 3233

speed, 7

split() method, 58

splitting strings into arrays, 58

starting

authentication, 79

MongoDB, 22

query routers, 473

shells, 28

statements

if, applying, 4344

return, 50

switch, implementing, 44

statistics, viewing, 9496, 443444

stats() method, 89, 95

status of database write requests, retrieving, 145

stopping MongoDB, 25

storage, GridFS Stores, 483

storageSize() method, 89

strategies, 7

strategies, applying replication, 461

strings

arrays

converting, 62

splitting, 58

combining, 58

manipulating, 5660

objects, escape codes, 56

substrings, searching, 58

words, replacing, 58

subdocuments, 9, 118. See also documents

subobjects, 13. See also objects

substrings, searching strings, 58

subtraction (‑) operator, 40

switch statements, implementing, 44

syntax, objects, 5354

T

[top]

tag ranges, configuring sharding, 475

testing databases, 31

text indexes, 439

throwing errors, 66

Time To Live. See TTL

toArray() method, 108, 191, 373

todb parameter, 434

top command, 451453

totalIndexSize() method, 89

totalSize() method, 89

troubleshooting

databases

managing, 443453

repairing, 453454

top command, 451453

try/catch blocks, 65

TTL (Time To Live), 17

TTL property, 440

types

data

JavaScript, 3839

MongoDB, 1011

of indexes, 438440

of loops, 4449

of replica sets, 460

of sharding servers, 469

U

[top]

unique property, 440

update operators, databases, 146147

update() method, 89, 188, 242, 254, 302, 305, 314, 371

updateExisting property, 145

updating documents, 15

collections, 151155, 243

Java applications, 241245

Node.js applications, 423427

PHP applications, 302305

Python applications, 358361

upserted property, 145

upserting documents

collections, 158160, 246

Java applications, 245249

Node.js applications, 427431

PHP applications, 305308

Python application, 361364

usability, 10

use <database> command, 28

use <new_database_name> command, 92

user accounts

authentication, starting, 79

formatting, 72

managing, 7078

user administrator accounts, formatting, 78

userAdminAnyDatabase role, 71

userAdmin role, 71

username parameter, 434

users

deleting, 77

documents, counting, 126

lists, 74

V

[top]

validate() method, 92

validating databases, 444446

values

arrays, searching documents based on, 117

documents, searching, 118

fields

searching based on, 117

searching distinct, 138140, 218221

functions, returning, 50

key, grouping objects, 169

null variables, 39

subdocuments, searching, 118

var keyword, 38

variables

defining, 3738

functions, passing, 50

scope, 5253

verbose option, 179

verbose setting, 24

version() method, 87

viewing

collections, 96

databases

lists, 91

stats, 9496

statistics, 443444

W

[top]

waited property, 145

while loops, 45

wnote property, 145

words, replacing strings, 58

write concerns

configuring, 143144

Node.js applications, 374

PHP applications, 257

Python applications, 317

write requests, retrieving status of database, 145

write_concern() method, 312-314

wtime property, 145

wtimeout property, 145