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, 78‑82

documents, counting, 125‑127

GridFS Stores, 484

files, 492‑493

Node.js applications, 498, 500‑501

Python, 494, 496‑497

HTTP interfaces, 26

Java applications, 209

applying aggregation, 225‑228

finding distinct field values, 218‑221

grouping results, 221‑225

limiting result sets, 209‑218

MongoDB shell clients, 27‑31

MongoGridFS objects in PHP, 490

Node.js applications, 391

applying aggregation, 406‑409

limiting result sets, 391‑399

objects, 12

PHP applications, 273

applying aggregation, 287‑290

grouping results, 283‑287

limiting result sets, 273‑281

searching distinct field values, 281‑283

Python application, 331

applying aggregation, 344‑347

grouping results, 341

limiting result sets, 331‑338

accounts

authentication, starting, 79

database administrator, formatting, 79

users

administrator, formatting, 78

formatting, 72

managing, 70‑78

accuracy, 7, 17

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

adding

documents

collections, 149‑151, 232

Java applications, 231‑235

Node.js applications, 411‑416

PHP applications, 293‑297

Python application, 349‑353

error handling, 65‑67

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

indexes, 438‑440

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, 78‑82

overview of, 69

user accounts, managing, 70‑78

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

aggregation

applying, 171‑178

Java, 225‑228

Node.js applications, 406‑409

operators

expression, 173‑175

framework, 174‑172

PHP applications, 287‑290

pipelines, 176

Python application, 344‑347

analyzing queries, 449‑451

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, 171‑178

Java, 225‑228

Node.js applications, 406‑409

PHP applications, 287‑290

pipelines, 176

Python application, 344‑347

anonymous functions, 51

arrays, 60‑65

if statements, 43‑44

indexes, 438‑443

replication, 459‑467

results, mapReduce() method, 178‑183

arbiter servers, 460

arithmetic operators, 40‑41

Array objects, PHP applications, 257

arrays, 39

applying, 60‑65

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, 454‑455

MongoDB, 454‑455

BasicDBObject object, Java applications, 191‑194

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, 14‑15, 436‑437

changeUserPassword() method, 87

characters, null, 9

clients, shells

accessing MongoDB from, 27‑31

scripting, 33‑34

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, 475‑479

code property, 145

collection_names() method, 313

Collection object, 89

Node.js applications, 370‑371

Python application, 313

collections, 9

capped, formatting, 14‑15, 436‑437

databases, managing, 433‑437

deleting, 98‑100

design, 16

documents. See also documents

adding, 149‑151, 232

configuring write concerns, 143‑144

database update operators, 146‑147

deleting, 161‑163, 236

error handling, 144

manipulating, 143

paging, 136

PHP applications, 294

retrieving, 112‑116

saving, 155‑158, 239

status of database write requests, 145

updating, 151‑155, 243

upserting, 158‑160, 246

formatting, 96‑98

lists, viewing, 96

managing, 96

reindexing, 441‑443

renaming, 435‑436

sharding, enabling, 474

statistics, viewing, 443‑444

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, 482‑483

parameters, 30‑31

shells, 28, 32‑33

top, 451‑453

use <new_database_name>, 92

comparison operators, 42

compound indexes, 439

cond parameter, 168

config servers, 470, 472

configuring

access control, 78‑82

databases, 22

error handling, 144

MongoDB, 23‑26

PHP application write concerns, 257

servers, 461

sharding tag ranges, 475

write concerns, 143‑144

connect() method, 186, 252, 368

Connection objects, overview of, 86

connectionId property, 145

connections

databases, configuring error handling, 144

write concerns, configuring, 143‑144

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, 434‑435

copyTo() method, 89

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

counting documents, 125‑127

Java applications, 201‑203

Node.js applications, 383‑385

PHP applications, 265‑267

Python application, 324‑326

countWords() method, 202

create_collection() method, 313

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

createIndex() method, 89

current() method, 256

Cursor objects, 107‑108

documents, counting, 126

Node.js applications, 373

Python applications, 315, 324, 327, 332

results

limiting, 130‑138

sorting, 128‑130

customizing objects, defining, 54‑55

D

[top]

data life cycles, 17

data types

JavaScript, 38‑39

MongoDB, 10‑11

<database> command, 87

Database object, 86‑87

Node.js applications, 369‑370

Python applications, 313

database_names() method, 312

databases

access control, implementing, 80

admin, overview of, 69

administrator accounts, formatting, 79

backing up, 454‑455

Collection object, 89

collections, managing, 433‑437

column store, 7

configuring, 22

Connection objects, overview of, 86

connections, configuring error handling, 144

copying, 434‑435

deleting, 93‑94

document store, 6

formatting, 92‑93

graph store, 7

indexes, 438‑443

key‑value, 6

lists, viewing, 91

managing, 91

optimizing, 443‑453

repairing, 453‑454

modifying, 92

profiling, 446‑448

queries, evaluating, 449‑451

results

grouping, 167‑171

limiting, 130‑138

sorting, 128‑130

roles, assigning, 71

selecting, 7‑8

sharding, enabling, 474

shells, managing, 433

statistics, viewing, 94‑96, 443‑444

testing, 31

top command, 451‑453

update operators, 146‑147

users, listing, 74

validating, 444‑446

write concerns, configuring, 143‑144

dataset examples, implementing, 100‑103

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, 189‑191, 202, 204, 210, 213

DBObject objects, 191‑194

declaring variables, 38

decrement (‑‑) operator, 40

default_id indexes, 439

defining

documents, 13

functions, 49

objects, customizing, 54‑55

variables, 37‑38

deleting

collections, 98‑100

databases, 93‑94

documents

collections, 236

Java applications, 236‑238

Node.js applications, 416‑419

PHP applications, 297‑299

Python application, 353‑355

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

indexes, 441

items from arrays, 63

objects, 12

users, 77

denormalizing data, 13‑14

deploying

replica sets, 462‑463

sharding clusters, 472

design, 6, 16

diagnostics, managing databases, 443‑453

Dictionary objects, PHP applications, 317

displayGroup() method, 284

displayWords() method, 131

distinct field values

Node.js applications, 400‑402

PHP applications, 281‑283

Python applications, 339‑341

searching, 138‑140, 218‑221

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, 149‑151, 232

configuring write concerns, 143‑144

database update operators, 146‑147

deleting, 161‑163, 236

error handling, 144

retrieving, 112‑116

saving, 155‑158, 239

status of database write requests, 145

updating, 151‑155, 243

upserting, 158‑160, 246

counting, 125‑127

Cursor objects, 107‑108

distinct field values, retrieving, 139

embedding, denormalizing data, 13‑14

Java applications

adding, 231‑235

counting, 201‑203

deleting, 236‑238

saving, 239‑241

searching, 194‑201

sorting results, 203‑206

updating, 241‑245

upserting, 245‑249

manipulating, 143

Node.js applications, 411

adding, 411‑416

counting, 383‑385

deleting, 416‑419

grouping results, 402‑406

objects used as, 374

paging, 397

retrieving, 377‑383

saving, 419‑423

searching distinct field values, 400‑402

sorting results, 385‑388

updating, 423‑427

upserting, 427‑431

overview of, 9‑10

parameters, PHP Arrays objects as, 257

PHP applications, 293

adding, 293‑297

counting, 265‑267

deleting, 297‑299

reviewing, 260‑262

saving, 299‑302

searching, 259‑265

sorting results, 267‑270

updating, 302‑305

upserting, 305‑308

Python application, 349

adding, 349‑353

counting, 324‑326

deleting, 353‑355

saving, 355‑357

searching, 318‑324

sorting results, 326‑328

updating, 358‑361

upserting, 361‑364

references, normalizing data, 12‑13

results

limiting, 130‑138

sorting, 128‑130

shells, searching in, 112‑116

sizing, 10

specific, retrieving (using PHP), 262‑265

specific sets of, searching, 117‑122

updating, 15

values, searching, 118

do/while loops, 45

drivers

Java applications, 185‑194

Node.js applications, 367‑377

PHP applications, 251‑259

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, 13‑14

enabling sharding

collections, 474

databases, 474

engines, starting/stopping, 22

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

err property, 145

errors

handling

adding, 65‑67

document collections, 144

throwing, 66

escape codes, string objects, 56

‑‑eval command‑line option, 31‑32

eval() method, 87

evaluating

queries, 449‑451

shells, expressions, 31‑32

example datasets, implementing, 100‑103

executing

shell scripting, 32

variables, 38

exit command, 28

expression operators, aggregation, 173‑175

expressions, evaluating shells, 31‑32

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, 138‑140, 218‑221

fields:value operator, 110

files

configuration settings, 24

GridFS Stores

adding, 485, 491, 494, 498

deleting, 486, 491, 495, 499

listing, 485

manipulating, 492‑493

retrieving, 486, 491, 495, 499

JavaScript, specifying, 32‑33

finalize option, 179

finalize parameter, 168

finally blocks, 66

find operations

PHP applications, 283‑287

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, 167‑171, 221‑225

for loops, 45‑46

for/in loops, 46‑47

forEach() method, 108

formatting. See also design

capped collections, 14‑15, 436‑437

collections, 96‑98

config servers, instances, 472

database administrator accounts, 79

databases, 92‑93

example datasets, 101

functions, 49‑52

replica sets, 463‑467

sharding clusters, 475‑479

users

accounts, 72

administrator accounts, 78

frameworks, aggregation operators, 174‑172

fromdb parameter, 434

fromhost parameter, 434

functions

anonymous, applying, 51

callback, 368

defining, 49

formatting, 49‑52

greeting(), 50

print(), 32

values, returning, 50

variables, passing, 50

G

[top]

generating new data results, 178‑183

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, 492‑493

retrieving, 486, 491, 495, 499

implementing, 481

Java, 484‑489

Node.js applications

accessing, 498, 500‑501

implementing, 497‑501

overview of, 481‑482

PHP, 489‑493

Python

accessing, 496‑497

implementing, 494‑497

shells, implementing, 482‑484

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

grouping

objects, 169, 284

results, 167‑171, 221‑225

Node.js applications, 402‑406

PHP applications, 283‑287

Python applications, 341

growth, documents, 15. See also updating

H

[top]

handling errors, 65‑67

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, 43‑44

implementing, 6

access control, 80

example datasets, 100‑103

GridFS Stores, 481

Java, 484‑489

Node.js applications, 497‑501

PHP, 489‑493

Python, 494‑497

shells, 482‑484

in Java applications, 185. See also Java applications

looping, 44‑49

replication, 459

sharding, 459, 468‑479

strategies, 7

switch statements, 44

upsert, 158

increment (++) operator, 40

indexes, 16

adding, 438‑440

collections, reindexing, 441‑443

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, 191‑194

data access, 209

applying aggregation, 225‑228

finding distinct field values, 218‑221

grouping results, 221‑225

limiting result sets, 209‑218

DB object, 187

DBCollection object, 188

DBCursor object, 202, 204, 210

DBObject objects, 191‑194

documents

adding, 231‑235

counting, 201‑203

deleting, 236‑238

saving, 239‑241

searching, 194‑201

sorting results, 203‑206

updating, 241‑245

upserting, 245‑249

driver objects, 185‑194

GridFS Stores, implementing, 484‑489

MongoClient object, 186

results, paging, 215

JavaScript

arrays, applying, 60‑65

data types, 38‑39

error handling, adding, 65‑67

files, specifying, 32‑33

functions, formatting, 49‑52

looping, implementing, 44‑49

objects, 53‑56

operators, 40‑44. See also operators

shells, 30, 40

strings, manipulating, 56‑60

variables

defining, 37‑38

scope, 52‑53

journal setting, 24

jsMode option, 179

K

[top]

key‑value databases, 6

keyf parameter, 168

keys

parameters, 168, 434

sharding, selecting, 470‑471

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, 130‑138, 209‑218

results

Node.js applications, 391‑399

PHP applications, 273‑281

Python application, 331‑338

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, 490‑491

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, 45‑46

for/in loops, 46‑47

implementing, 44‑49

interrupting, 47

variables, 38

while loops, 45

M

[top]

main() method, 202

managing

access control, configuring, 78‑82

collections, 96

configuration settings, 23

databases, 91

collections, 433‑437

indexes, 438‑443

optimizing, 443‑453

repairing, 453‑454

shells, 433

user accounts, 70‑78

manipulating. See also modifying

arrays, 61

documents, 143

GridFS Stores

files, 492‑493

Node.js applications, 500‑501

Python, 496‑497

requests, applying aggregation, 171‑178

results, 181

strings, 56‑60

map() method, 108, 131

mapReduce() method, 89, 188

results, applying, 178‑183

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, 178‑183, 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, 471‑472

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, 11‑17

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, 253‑254

MongoCursor object, PHP applications, 256, 274-276

MongoDB. See also databases

backing up, 454‑455

configuring, 23‑26

data types, 10‑11

HTTP interfaces, accessing, 26

installing, 22

Java applications. See Java applications

overview of, 8‑10

shells

accessing clients, 27‑31

scripting, 31‑34

starting, 22

stopping, 25

MongoDB object, PHP applications, 253

mongofiles command, 482‑483

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, 370‑371

Cursor objects, 373

data access, 391

applying aggregation, 406‑409

grouping results, 402‑406

limiting result sets, 391‑399

Database object, 369‑370

documents, 411

adding, 411‑416

counting, 383‑385

deleting, 416‑419

paging, 397

retrieving, 377‑383

saving, 419‑423

searching distinct field values, 400‑402

sorting results, 385‑388

updating, 423‑427

upserting, 427‑431

driver objects, 367‑377

GridFS Stores

accessing, 498, 500‑501

implementing, 497‑501

MongoClient object, 368

objects used as documents/parameters, 374

specific documents, 380

nohttpinterface setting, 24

normalizing data, 12‑13

NoSQL

overview of, 6

selecting, 7‑8

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, 191‑194

Collection, 89

Connection, overview of, 86

Cursor, 107‑108

counting documents, 126

limiting results, 130‑138

sorting results, 128‑130

Database, 86‑87

DB, 187

DBCollection, 188

DBCursor, 189‑191, 202, 204, 210

DBObject, 191‑194

defining, customizing, 54‑55

drivers

Java applications, 185‑194

Node.js applications, 367‑377

PHP applications, 251‑259

fields, limiting, 132, 212

grouping, 169

JavaScript, 53‑56

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, 53‑54

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, 173‑175

framework, 174‑172

and (&&), 42

arithmetic, 40‑41

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, 40‑44

modulous (%), 40

multiplication (*), 40

not (!), 42

or (||), 42

query, 109‑110

subtraction (‑), 40

update, 146‑147

optimizing databases, 443‑453

options, ‑‑eval command‑line, 31‑32

orders, sorting, 128‑130

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, 30‑31

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, 471‑472

passing variables to functions, 50

patterns, prototyping objects, 55

performance, 17

databases, managing, 443‑453

models, planning, 11‑17

replication, 460. See also replication

PHP applications, 251

Array objects, 257

data access, 273

applying aggregation, 287‑290

grouping results, 283‑287

limiting result sets, 273‑281

searching distinct field values, 281‑283

DB object, 253

DBCollection object, 279

Dictionary objects, 317

documents, 293

adding, 293‑297

counting, 265‑267

deleting, 297‑299

reviewing, 260‑262

saving, 299‑302

searching, 259‑265

sorting results, 267‑270

updating, 302‑305

upserting, 305‑308

driver objects, 251‑259

fields, limiting, 276

GridFS Stores, implementing, 489‑493

MongoClient object, 252

MongoCollection object, 253‑254

MongoCursor object, 256, 274-276

MongoDB object, 253

results, paging, 278

write concerns, configuring, 257

pipelines, applying aggregation, 176

planning models, 11‑17

port setting, 24

primary servers, 460

print() function, 32

print() method, 40

printjson() method, 40

privileges, clusterAdmin role, 91

profiling databases, 446‑448

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, 344‑347

grouping results, 341

limiting result sets, 331‑338

Database object, 313

distinct field values, 339‑341

documents, 349

adding, 349‑353

counting, 324‑326

deleting, 353‑355

saving, 355‑357

searching, 318‑324

sorting results, 326‑328

updating, 358‑361

upserting, 361‑364

fields, limiting, 334

GridFS Stores

accessing, 496‑497

implementing, 494‑497

MongoClient object, 312

results, paging, 336

Q

[top]

queries

evaluating, 449‑451

routers, 469

starting, 473

query operators, 109‑110

query options, 179

query parameters, 139, 161

R

[top]

RAM (random access memory), 10

random access memory. See RAM

RDBMSs (relational database management systems), 6‑8

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, 12‑13

reIndex() method, 89

reindexing collections, 441‑443

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, 435‑436

repairDatabase() method, 87

repairing databases, 453‑454

replacing words in strings, 58

replica sets. See also replication

deploying, 462‑463

formatting, 463‑467

types of, 460

replication, 16, 459

applying, 459‑467

strategies, applying, 461

requests

manipulating, applying aggregation, 171‑178

Node.js applications, 374

paging, 128

PHP applications, applying aggregation, 287‑290

status of database write, retrieving, 145

resetDoc() method, 242

REST interfaces, 26

rest setting, 24

results, 30‑31

grouping, 167‑171, 221‑225

Java applications

paging, 215

sorting, 203‑206

limiting

Java applications, 209‑218

PHP applications, 273‑281

manipulating, 181

mapReduce() method, applying, 178‑183

Node.js applications

grouping, 402‑406

limiting, 391‑399

sorting, 385‑388

paging, 136

PHP applications

grouping, 283‑287

paging, 278

sorting, 267‑270

Python application

limiting, 331‑338

sorting, 326‑328

Python applications

grouping, 341

paging, 336

sets, limiting, 130‑138

sorting, 128‑130

retrieving

distinct field values, 139, 219, 282, 400

documents

from collections, 112‑116

Node.js applications, 377‑383

Python applications, 319

using Java, 195

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

specific documents (using PHP), 262‑265

status of database write requests, 145

return keyword, 50

returning

fields, limiting, 212

objects, 132

values from functions, 50

reviewing documents, PHP applications, 260‑262

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, 454‑455

documents

collections, 155‑158, 239

Java applications, 239‑241

Node.js applications, 419‑423

PHP applications, 299‑302

Python application, 355‑357

scalability, 6

scope

options, 179

variables, 52‑53

scripting shells, 31‑34

clients, 33‑34

executing, 32

searching

array items, 63

contents, 118

distinct field values, 138‑140, 218‑221

Node.js applications, 400‑402

PHP applications, 281‑283

documents

in shells, 112‑116

Java applications, 194‑201

Node.js applications, 377‑383

PHP applications, 259‑265

Python application, 318‑324

multiple documents, 115

results, grouping, 167‑171

specific documents, Node.js applications, 380

specific sets of documents, 117‑122

substrings in strings, 58

secondary servers, 460

selectCollection() method, 252-253

selectDB() method, 252

selecting

NoSQL, 7‑8

partitioning methods, 471‑472

RDBMS, 7‑8

sharding keys, 470‑471

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, 203‑206

limiting, 130‑138

limiting access in Java applications, 209‑218

PHP applications, 273‑281

setSlaveOk() method, 86

setup. See configuring

setWriteConcern() method, 186-188

shard servers, 469

sharding, 16, 459

clusters

adding, 473

deploying, 472

formatting, 475‑479

collections, enabling, 474

databases, enabling, 474

implementing, 468‑479

keys, selecting, 470‑471

servers, types of, 469

tag ranges, configuring, 475

shells

aggregation, applying, 171‑178

clients

accessing MongoDB from, 27‑31

scripting, 33‑34

commands, 28, 32‑33

constructors, 29

databases, managing, 433

documents

adding to collections, 149‑151

counting, 125‑127

deleting, 161‑163

limiting result sets, 130‑138

saving, 155‑158

searching in, 112‑116

sorting results, 128‑130

updating, 151‑155

upserting, 158‑160

expressions, evaluating, 31‑32

GridFS Stores, implementing, 482‑484

JavaScript, 30, 40

native methods, 29

objects, grouping, 222

results

grouping, 167‑171

mapReduce() method, 178‑183

scripting, 31‑34

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, 392‑394

results, limiting by, 210

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

slaveOk parameter, 434

snapshot() method, 108

sorting results, 128‑130

Java applications, 203‑206

Node.js applications, 385‑388

PHP applications, 267‑270

Python application, 326‑328

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, 262‑265

Python applications, 321

specific sets of documents, searching, 117‑122

specifying JavaScript files, 32‑33

speed, 7

split() method, 58

splitting strings into arrays, 58

starting

authentication, 79

MongoDB, 22

query routers, 473

shells, 28

statements

if, applying, 43‑44

return, 50

switch, implementing, 44

statistics, viewing, 94‑96, 443‑444

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, 56‑60

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, 53‑54

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, 451‑453

totalIndexSize() method, 89

totalSize() method, 89

troubleshooting

databases

managing, 443‑453

repairing, 453‑454

top command, 451‑453

try/catch blocks, 65

TTL (Time To Live), 17

TTL property, 440

types

data

JavaScript, 38‑39

MongoDB, 10‑11

of indexes, 438‑440

of loops, 44‑49

of replica sets, 460

of sharding servers, 469

U

[top]

unique property, 440

update operators, databases, 146‑147

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

updateExisting property, 145

updating documents, 15

collections, 151‑155, 243

Java applications, 241‑245

Node.js applications, 423‑427

PHP applications, 302‑305

Python applications, 358‑361

upserted property, 145

upserting documents

collections, 158‑160, 246

Java applications, 245‑249

Node.js applications, 427‑431

PHP applications, 305‑308

Python application, 361‑364

usability, 10

use <database> command, 28

use <new_database_name> command, 92

user accounts

authentication, starting, 79

formatting, 72

managing, 70‑78

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, 444‑446

values

arrays, searching documents based on, 117

documents, searching, 118

fields

searching based on, 117

searching distinct, 138‑140, 218‑221

functions, returning, 50

key, grouping objects, 169

null variables, 39

subdocuments, searching, 118

var keyword, 38

variables

defining, 37‑38

functions, passing, 50

scope, 52‑53

verbose option, 179

verbose setting, 24

version() method, 87

viewing

collections, 96

databases

lists, 91

stats, 94‑96

statistics, 443‑444

W

[top]

waited property, 145

while loops, 45

wnote property, 145

words, replacing strings, 58

write concerns

configuring, 143‑144

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