MongoDB

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

batch insert

...

embedded document

A document contained by a parent document. The embedded document is a value of a key in the parent document.

db.<collection>.insert({document});

Adds a document to a collection.

$addToSet

Adds a value to the array only if its not in the array already. Otherwise, if the field is not present, it sets the field to the array value. ex: { $addToSet : { a : { $each : [ 3 , 5 , 6 ] } } }

$push

Appends a value to field, if the field is an existing array. Otherwise it sets the field to the array [value] if field is not present. ex: { $push : { field : value } }

$pushAll

Appends each value in the value_array to the field, if field is an existing array. Otherwise, it sets the field to the array value_array, if field is not present ex: { $pushAll : { field : value_array } }

$all

Array specific conditional allowing matching on multiple elements within an array. The operation is non strict on the sequence of the values in the passed selector array. ex: db.<col>.find({arrField:{$all: [1,2,3]}});

$size

Array specific conditional used to select based on the length or set-size of an array field value. ex: db.<col>.find{{arrVal: {$size: {$gt:0}}});

BSON

Binary-encoded serialization of mongo documents.

db.cloneDatabase(fromhost)

Clone the current database (implied by 'db') from another host.

db.<col>.help([commandName]);

Command to get help docs on a specific command at the collection level.

db.help([commandName]);

Command to get help docs on a specific command at the db level.

help

Command to list commands and descriptions of those commands in the context of the database.

$in

Contains query conditional used to check if a value contains the field value. ex: db.<col>.find({numVal: {$in: [1,2,3]}});

db.copyDatabase(frmDBName, toDBName, [frmHostName], [user], [pwd]);

Copies an entire database from one name on one server to another name on another server. Omit frmHostName to copy from one name to another on the same server.

db.myCollection.ensureIndex({keypattern},[{options}])

Creates an index on property(s). Options can describe the type of sorting, uniqueness, etc.

document

Data structure used to store all other data in mongo databases.

$unset

Deletes a given field. ex: { $unset : { field : 1} }

db.<col>.remove({selector});

Deletes documents from the collection based on the selector.

$nin

Does not contain query conditional used to select documents with the field that is not in the selector list of values. ex: db.<col>.find({numVal: {$nin: [1,2,3]}});

db.runCommand({fsync:1,lock:1,async:1})

Flushes all pending writes to data files. The lock option allows one to safely snapshot the database's data files. The async option returns focus to the console immediately while the task runs in the background.

$gte

Greater than or equal query conditional. ex: db.<col>.find({numVal: {$gte:3}});

$gt

Greater than query conditional. ex: db.<col>.find({numVal: {$gt:3}});

maximum value

In BSON, represents the largest possible value.

minimum value

In BSON, represents the smallest possible value.

code

Javascript code. Documents can contain code as values.

$lte

Less than or equal query conditional. ex: db.<col>.find({numVal: {$lte:3}});

$lt

Less than query conditional. ex: db.<col>.find({numVal: {$lt:3}});

show collections

Lists all the collections in the database in use.

$mod

Meta query conditional generating a modulus with the selector operand. Checks to see if the field value when divided by one value has the remainder of the second value. ex: db.<col>.find({age: {$mod: [2,3]}});

$not

Meta query conditional used to negate the selector. ex: db.<col>.find({numVal: {$not:{{$in: [1,2,3]}}});

$ne

Not equal query conditional. ex: db.<col>.find({numVal: {$ne:3}});

32-Bit Integer

Not supported by the javascript shell and are converted to 64-bit floating point numbers.

64-Bit Integer

Not supported by the javascript shell and are converted to 64-bit floating point numbers.

$where

Operator allowing the execution of arbitrary javascript as part of the selector. The function or boolean comparative statement which is the arbitrary javascript returns a boolean indicating whether or not the document on which the function operated should be included in the result set.

$elemMatch

Operator allowing the partial specification of fields in an embedded document in an array. Otherwise, an exact match would be required on the embedded document in that position in the array to return the parent document. ex: db.<col>.find({arrDocs: {$elemMatch: {field1Of10:"bob", field8Of10:"sally"}}});

$slice

Operator used in the second argument of the find() call to specify which slice of an array to return for an array field. ex: db.<col>.find({selector}, {arrVal: {$slice: [1,3]}});

$

Positional operator that holds the position of the first matched array item in the query. Used to find an array member and then manipulate it. ex: {$inc:{'comments.$.votes':1}} where comments looks like: "comments" : [ { "by" : "joe", "votes" : 3 }, { "by" : "jane", "votes" : 7 } ]

$or

Query conditional allowing the selector to choose between more than one optional criteria. ex: db.<col>.find({$or:{numVal:1,numVal:8}});

$pull

Removes all occurrences of a value from a field. ex: { $pull : { field : _value } }

$pullAll

Removes all occurrences of each value in the passed in array from the field. ex: { $pullAll : { field : value_array } }

$pop

Removes an element from an array based on the value of the field option being 1 or -1 for last or first element respectively. ex: { $pop : { field : -1 } }

$rename

Renames a field from the one indicated to the new field name. ex: { $rename : { old_field_name : new_field_name } }

db.<collection>.find([properties]);

Returns all the documents matching the optional properties.

db.commandHelp("commandName")

Returns help information for a command.

db.getLastError()

Returns information about the last operation. Not necessarily error data, the return can contain things like number of records updated.

db.<collection>.findOne([properties]);

Returns one document matching the optional properties.

Object.bsonsize({document});

Returns the size of a document after it is converted to BSON from the JSON-like original.

array

Set or list of values.

Update Modifiers

Special keys passed in an update call to specify complex update operations, such as alter, adding, or removing keys, and even manipulating arrays and embedded documents.

boolean

Standard binary data type.

regular expression

Standard javascript regular expressions. These can be stored in documents

date

Stored as milliseconds since the epoch.

binary data

String of arbitrary bytes.

key.index

Syntax used for selectors to be specific to a certain element position within an array. ex: db.<col>.find({arrField.2:"eggs"});

Cursor

The local variable representation of a query. Uniquely, the cursor does not hold the results but instead access to the results.

64-bit floating point numbers

The standard number representation in the javascript shell.

object id

Unique 12-byte ID for documents.

db.<col>.update({selector},{document});

Update a document in the collection.

Upsert

Update call that inserts a new document if no update match is found. Allows the same code to be used for inserts as well as updates. Upsert is indicated by a third parameter which is a boolean in the update statement. ex: db.<col>.update({selector},{document},true);

$set

Update modifier that set the value of a key and if the key does not exist, it will create the key. ex: db.<col>.update({selector},{"$set":{"someKey":"someValue"}});

$inc

Update modifier used to increment a value. ex: {"$inc":{"counter":2}}

Multi-updates

Updates all matching documents, not just the first, that match the selector. This behavior is chosen by passing a boolean to the fourth update call parameter. ex: db.<col>.update({selector},{document},<upsertBool>,true});

undefined

Used to describe a variable as not having been initialized.

null

Used to represent both a null value and a nonexistent field.

use <database name>

changes the database on which you are working.

mongo

command to start the mongo shell.

mongod

command to start the mongodb process.

string

set of UTF-8 characters.


Ensembles d'études connexes

Microbiology Chapter 6 Part 2 HW

View Set

Chapter 27: Growth and Development of the Preschooler - ML6

View Set

Chapter 10 Quiz Question Bank - CIST1601-Information Security Fund

View Set

Pathophysiology Test 2 Objectives

View Set

Evolve - Chapter 20 (Cholinergic Drugs)

View Set

Internal Organ Functions & Locations

View Set

Anatomy and Physiology 2 Chapter 25

View Set