javathunderman 2016-01-15 22:27:24 +00:00
commit 3b446e082e
1 changed files with 0 additions and 241 deletions

View File

@ -1,241 +0,0 @@
{
"id": "mongodb_cheat_sheet",
"name": "MongoDB",
"description": "Mongo shell",
"template_type": "terminal",
"metadata": {
"sourceName": "Code Centric Blog",
"sourceUrl": "https://blog.codecentric.de/files/2012/12/MongoDB-CheatSheet-v1_0.pdf"
},
"section_order": ["Basic Conceptes & Shell Commands", "BSON Types", "Inserting Documents", "Finding Documents", "Finding Documents using Operators", "Updating Documents", "Removing Documents", "Working with Indexes", "Indexes - Hints & Stats", "Top & Stats System Commands", "Pipeline Stages", "Comparison with SQL", "Replica Sets", "Sharding", "Durability of Writes"],
"sections": {
"Basic Conceptes & Shell Commands": [{
"key": "db.ships.<command>",
"val": "db implicit handle to the used database, ships name of the used collection"
}, {
"key": "use <database>",
"val": "Switch to another database"
}, {
"key": "show collections",
"val": "Lists the available collections"
}, {
"key": "help",
"val": "Prints available commands and help"
}],
"BSON Types": [{
"key": "Double",
"val": "1"
}, {
"key": "String",
"val": "2"
}, {
"key": "Object",
"val": "3"
}, {
"key": "Array",
"val": "4"
}, {
"key": "Binary Data",
"val": "5"
}, {
"key": "Undefined",
"val": "6(Deprecated)"
}, {
"key": "Obect Id",
"val": "7"
}, {
"key": "Boolean",
"val": "8"
}, {
"key": "Date",
"val": "9"
}, {
"key": "Null",
"val": "10"
}],
"Inserting Documents": [{
"key": "db.ships.insert(\\{name:'USS Enterprise-D',operator:'Starfleet',type:'Explorer',class:'Galaxy',crew:750,codes:\\[10,11,12\\]\\})",
"val": "Insert into Ships collection Example 1"
}, {
"key": "db.ships.insert(\\{name:'IKS Buruk',operator:' Klingon Empire',class:'Warship',crew:40,codes:\\[100,110,120\\]\\})",
"val": "Insert into Ships collection Example 2"
}, {
"key": "db.ships.insert(\\{name:'Narada',operator:'Romulan Star Empire',type:'Warbird',class:'Warbird',crew:65,codes:\\[251,251,220\\]\\})",
"val": "Insert into Ships collection Example 3"
}],
"Finding Documents": [{
"key": "db.ships.findOne()",
"val": "Finds one arbitrary document"
}, {
"key": "db.ships.find().prettyPrint()",
"val": "Finds all documents and using nice formatting"
}, {
"key": "db.ships.find(\\{\\}, \\{name:true, _id:false\\})",
"val": "Shows only the names of the ships collections"
}, {
"key": "db.ships.findOne(\\{'name':'USS Defiant'\\})",
"val": "Finds one document by corresponding attribute"
}],
"Finding Documents using Operators": [{
"key": "$gt \/ $gte",
"val": "(greater than / greater than equals) : db.ships.find(\\{class:\\{$gt:P'\\}\\})"
}, {
"key": "$lt \/ $lte",
"val": "(lesser than / lesser than equals) : db.ships.find({class:{$lte:P'}})"
}, {
"key": "$exists",
"val": "(does an attribute exist or not) : db.ships.find({type:{$exists:true}})"
}, {
"key": "$regex",
"val": "(Perl-style pattern matching) : db.ships.find({name:{$regex:^USS\\sE}})"
}, {
"key": "$type",
"val": "(search by type of an element) : db.ships.find({name : {$type:2}})"
}],
"Updating Documents": [{
"key": "db.ships.update(\\{name : 'USS Prometheus'\\}, \\{name : 'USS Something'\\})",
"val": "Replaces the whole document"
}, {
"key": "db.ships.update(\\{name : 'USS Something'\\},\\{$set : \\{operator : 'Starfleet', class : 'Prometheus'\\}\\})",
"val": "sets / changes certain attributes of a given document"
}, {
"key": "db.ships.update(\\{name : 'USS Something'\\},\\{$unset : \\{operator : 1\\}\\})",
"val": "removes an attribute from a given document"
}],
"Removing Documents": [{
"key": "db.ships.remove(\\{name : 'USS Prometheus'\\})",
"val": "removes the document"
}, {
"key": "db.ships.remove(\\{name:\\{$regex:^USS\\sE\\}\\})",
"val": "removes using operator"
}],
"Working with Indexes": [{
"key": "db.ships.ensureIndex(\\{name : 1\\})",
"val": "Creating an index"
}, {
"key": "db.ships.dropIndex(\\{name : 1\\})",
"val": "Dropping an index"
}, {
"key": "db.ships.ensureIndex(\\{name : 1, operator : 1, class : 0\\})",
"val": "Creating a compound index"
}, {
"key": "db.ships.dropIndex(\\{name : 1, operator : 1, class : 0\\})",
"val": "Dropping a compound index"
}, {
"key": "db.ships.ensureIndex(\\{name : 1, operator : 1, class : 0\\}, \\{unique : true\\})",
"val": "Creating a unique compound index"
}],
"Indexes - Hints & Stats": [{
"key": "db.ships.find (\\{'name':'USS Defiant'\\}).explain()",
"val": "Explains index usage"
}, {
"key": "db.ships.stats()",
"val": "Index statistics"
}, {
"key": "db.ships.totalIndexSize()",
"val": "Index size"
}],
"Top & Stats System Commands": [{
"key": "./mongotop",
"val": "Shows time spent per operations per collection"
}, {
"key": "./mongostat",
"val": "Shows snapshot on the MongoDB system"
}],
"Pipeline Stages": [{
"key": "$project",
"val": "Change the set of documents by modifying keys and values. This is a 1:1 mapping."
}, {
"key": "$match",
"val": "This is a filtering operation and thus this can reduce the amount of documents that are given as input to the next stage. This can be used for example if aggregation should only happen on a subset of the data."
}, {
"key": "$group",
"val": "This does the actual aggregation and as we are grouping by one or more keys this can have a reducing effect on the amount of documents."
}, {
"key": "$sort",
"val": "Sorting the documents one way or the other for the next stage. It should be noted that this might use a lot of memory. Thus if possible one should always try to reduce the amount of documents first."
}, {
"key": "$skip",
"val": "With this it is possible to skip forward in the list of documents for a given amount of documents. This allows for example starting only from the 10th document. Typically this will be used together with “$sort” and especially together with “$limit”."
}, {
"key": "$limit",
"val": "This limits the amount of documents to look at by the given number starting from the current position."
}, {
"key": "$unwind",
"val": "This is used to unwind document that are using arrays. When using an array the data is kind of pre-joined and this operation will be undone with this to have individual documents again. Thus with this stage we will increase the amount of documents for the next stage."
}],
"Comparison with SQL": [{
"key": "$match",
"val": "WHERE"
}, {
"key": "$group",
"val": "GROUP BY"
}, {
"key": "$match",
"val": "HAVING"
}, {
"key": "$project",
"val": "SELECT"
}, {
"key": "$sort",
"val": "ORDER BY"
}, {
"key": "$limit",
"val": "LIMIT"
}, {
"key": "$sum",
"val": "SUM"
}, {
"key": "$sum",
"val": "COUNT"
}, {
"key": "$unwind",
"val": "JOIN"
}],
"Replica Sets": [{
"key": "Regular",
"val": "This is the most typical kind of node. It can act as a primary or secondary node"
}, {
"key": "Arbiter",
"val": "Arbiter nodes are only there for voting purposes. They can be used to ensure that there is a certain amount of nodes in a replica set even though there are not that many physical servers."
}, {
"key": "Delayed",
"val": "Often used as a disaster recovery node. The data stored here is usually a few hours behind the real working data."
}, {
"key": "Hidden",
"val": "Often used for analytics in the replica set."
}],
"Sharding": [{
"key": "1",
"val": "Every document has to define a shard-key."
}, {
"key": "2",
"val": "The value of the shard-key is immutable."
}, {
"key": "3",
"val": "The shard-key must be part of an index and it must be the first field in that index."
}, {
"key": "4",
"val": "There can be no unique index unless the shard-key is part of it and is then the first field."
}, {
"key": "5",
"val": "Reads done without specifying the shard-key will lead to requests to all the different shards."
}, {
"key": "6",
"val": "The shard-key must offer sufficient cardinality to be able to utilize all shards."
}],
"Durability of Writes": [{
"key": "w=0 && j=0",
"val": "This is “fire and forget”."
}, {
"key": "w=1 && j=0",
"val": "Waits for an acknowledgement that the write was received and no indexes have been violated. Data can still be lost."
}, {
"key": "w=1 && j=1",
"val": "The most save configuration by waiting for the write to the journal to be completed"
}, {
"key": "w=0 && j=1",
"val": "Basically as same as above."
}]
}
}