mirror of
https://github.com/m-lamonaca/dev-notes.git
synced 2025-06-08 10:47:13 +00:00
remove mkdocs specific syntax
This commit is contained in:
parent
8d08c1964f
commit
8026e1465b
77 changed files with 1128 additions and 1128 deletions
|
@ -25,7 +25,7 @@ MongoDB automatically creates an `ObjectId()` if it's not provided.
|
|||
To create a database is sufficient to switch towards a non existing one with `use <database>` (implicit creation).
|
||||
The database is not actually created until a document is inserted.
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
show dbs # list all databases
|
||||
use <database> # use a particular database
|
||||
show collections # list all collection for the current database
|
||||
|
@ -38,7 +38,7 @@ db.<collection>.insertOne({document}) # implicit collection creation
|
|||
|
||||
## Operators (MQL Syntax)
|
||||
|
||||
```json linenums="1"
|
||||
```json
|
||||
/* --- Update operators --- */
|
||||
{ "$inc": { "<key>": "<increment>", ... } } // increment value
|
||||
{ "$set": { "<key>": "<value>", ... } } // set value
|
||||
|
@ -83,7 +83,7 @@ db.<collection>.insertOne({document}) # implicit collection creation
|
|||
|
||||
> **Note**: `$<key>` is used to access the value of the field dynamically
|
||||
|
||||
```json linenums="1"
|
||||
```json
|
||||
{ "$expr": { "<expression>" } } // aggregation expression, variables, conditional expressions
|
||||
{ "$expr": { "$<comparison_operator>": [ "$<key>", "$<key>" ] } } // compare field values (operators use aggregation syntax)
|
||||
```
|
||||
|
@ -99,7 +99,7 @@ Insertion results:
|
|||
- error -> rollback
|
||||
- success -> entire documents gets saved
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
# explicit collection creation, all options are optional
|
||||
db.createCollection( <name>,
|
||||
{
|
||||
|
@ -132,7 +132,7 @@ db.<collection>.insertMany([ { document }, { document } ] , { "ordered": false }
|
|||
|
||||
### Querying
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.findOne() # find only one document
|
||||
db.<collection>.find(filter) # show selected documents
|
||||
db.<collection>.find().pretty() # show documents formatted
|
||||
|
@ -176,7 +176,7 @@ db.<collection>.find().hint( { $natural : -1 } ) # force the query to perform a
|
|||
|
||||
[Update Operators](https://docs.mongodb.com/manual/reference/operator/update/ "Update Operators Documentation")
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.replaceOne(filter, update, options)
|
||||
db.<collection>.updateOne(filter, update, {upsert: true}) # modify document if existing, insert otherwise
|
||||
|
||||
|
@ -185,7 +185,7 @@ db.<collection>.updateOne(filter, { "$push": { ... }, "$set": { ... }, { "$inc":
|
|||
|
||||
### Deletion
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.deleteOne(filter, options)
|
||||
db.<collection>.deleteMany(filter, options)
|
||||
|
||||
|
@ -203,7 +203,7 @@ Utility to import all docs into a specified collection.
|
|||
If the collection already exists `--drop` deletes it before reuploading it.
|
||||
**WARNING**: CSV separators must be commas (`,`)
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
mongoimport <options> <connection-string> <file>
|
||||
|
||||
--uri=<connectionString>
|
||||
|
@ -222,7 +222,7 @@ mongoimport <options> <connection-string> <file>
|
|||
|
||||
Utility to export documents into a specified file.
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
mongoexport --collection=<collection> <options> <connection-string>
|
||||
|
||||
--uri=<connectionString>
|
||||
|
@ -276,7 +276,7 @@ Indexes _slow down writing operations_ since the index must be updated at every
|
|||
|
||||
### Diagnosis and query planning
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.find({...}).explain() # explain won't accept other functions
|
||||
db.explain().<collection>.find({...}) # can accept other functions
|
||||
db.explain("executionStats").<collection>.find({...}) # more info
|
||||
|
@ -284,7 +284,7 @@ db.explain("executionStats").<collection>.find({...}) # more info
|
|||
|
||||
### Index Creation
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.createIndex( <key and index type specification>, <options> )
|
||||
|
||||
db.<collection>.createIndex( { "<key>": <type>, "<key>": <type>, ... } ) # normal, compound or multikey (field is array) index
|
||||
|
@ -306,7 +306,7 @@ db.<collection>.createIndex(
|
|||
|
||||
### [Index Management](https://docs.mongodb.com/manual/tutorial/manage-indexes/)
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
# view all db indexes
|
||||
db.getCollectionNames().forEach(function(collection) {
|
||||
indexes = db[collection].getIndexes();
|
||||
|
@ -343,7 +343,7 @@ handling connections, requests and persisting the data.
|
|||
|
||||
### Basic Shell Helpers
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<method>() # database interaction
|
||||
db.<collection>.<method>() # collection interaction
|
||||
rs.<method>(); # replica set deployment and management
|
||||
|
@ -382,7 +382,7 @@ Log Verbosity Level:
|
|||
- `0`: Default Verbosity (Information)
|
||||
- `1 - 5`: Increases the verbosity up to Debug messages
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.getLogComponents() # get components and their verbosity
|
||||
db.adminCommand({"getLog": "<scope>"}) # retrieve logs (getLog must be run on admin db -> adminCommand)
|
||||
db.setLogLevel(<level>, "<component>"); # set log level (output is OLD verbosity levels)
|
||||
|
@ -408,7 +408,7 @@ Events captured by the profiler:
|
|||
|
||||
> **Note**: Logs are saved in the `system.profile` _capped_ collection.
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.setProfilingLevel(n) # set profiler level
|
||||
db.setProfilingLevel(1, { slowms: <ms> })
|
||||
db.getProfilingStatus() # check profiler status
|
||||
|
@ -456,7 +456,7 @@ Built-in Roles Groups and Names:
|
|||
- Backup/Restore: `backup`, `restore`
|
||||
- Super User: `root`
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.createUser({
|
||||
user: "<username>",
|
||||
pwd: "<password>",
|
||||
|
@ -538,7 +538,7 @@ Variable syntax in aggregations:
|
|||
|
||||
Filters the documents to pass only the documents that match the specified condition(s) to the next pipeline stage.
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.aggregate([
|
||||
{ "$match": { "<query>" } },
|
||||
|
||||
|
@ -570,7 +570,7 @@ Passes along the documents with the requested fields to the next stage in the pi
|
|||
- [`$sum`][$sum_docs]
|
||||
- [`$avg`][$avg_docs]
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.aggregate([
|
||||
{
|
||||
"$project": {
|
||||
|
@ -627,7 +627,7 @@ db.<collection>.aggregate([
|
|||
Adds new fields to documents (can be result of computation).
|
||||
`$addFields` outputs documents that contain _all existing fields_ from the input documents and newly added fields.
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.aggregate({
|
||||
{ $addFields: { <newField>: <expression>, ... } }
|
||||
})
|
||||
|
@ -639,7 +639,7 @@ db.<collection>.aggregate({
|
|||
|
||||
The $`group` stage separates documents into groups according to a "group key". The output is one document for each unique group key.
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.aggregate([
|
||||
{
|
||||
"$group": {
|
||||
|
@ -658,7 +658,7 @@ db.<collection>.aggregate([
|
|||
Deconstructs an array field from the input documents to output a document for each element.
|
||||
Each output document is the input document with the value of the array field replaced by the element
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.aggregate([
|
||||
{ "$unwind": "<array-key>" }
|
||||
|
||||
|
@ -676,7 +676,7 @@ db.<collection>.aggregate([
|
|||
|
||||
### [`$count` Aggregation Stage][$count_docs]
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.aggregate([
|
||||
{ "$count": "<count-key>" }
|
||||
])
|
||||
|
@ -686,7 +686,7 @@ db.<collection>.aggregate([
|
|||
|
||||
### [`$sort` Aggregation Stage][$sort_docs]
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.aggregate([
|
||||
{
|
||||
"$sort": {
|
||||
|
@ -705,7 +705,7 @@ db.<collection>.aggregate([
|
|||
|
||||
### [`$skip` Aggregation Stage][$skip_docs]
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.aggregate([
|
||||
{ "$skip": "<positive 64-bit integer>" }
|
||||
])
|
||||
|
@ -715,7 +715,7 @@ db.<collection>.aggregate([
|
|||
|
||||
### [`$limit` Aggregation Stage][$limit_docs]
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.aggregate([
|
||||
{ "$limit": "<positive 64-bit integer>" }
|
||||
])
|
||||
|
@ -730,7 +730,7 @@ The `$lookup` stage adds a new array field to each input document. The new array
|
|||
|
||||
> **Note**: To combine elements from two different collections, use the [`$unionWith`][$unionWith_docs] pipeline stage.
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.aggregate([
|
||||
{
|
||||
"$lookup": {
|
||||
|
@ -753,7 +753,7 @@ Performs a recursive search on a collection, with options for restricting the se
|
|||
|
||||
The collection on which the aggregation is performed and the `from` collection can be the same (in-collection search) or different (cross-collection search)
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.aggregate([
|
||||
{
|
||||
$graphLookup: {
|
||||
|
@ -783,7 +783,7 @@ Each output document contains two fields: an `_id` field containing the distinct
|
|||
|
||||
The documents are sorted by count in descending order.
|
||||
|
||||
```sh linenums="1"
|
||||
```sh
|
||||
db.<collection>.aggregate([
|
||||
{ $sortByCount: <expression> }
|
||||
])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue