Last Sync: 2022-08-12 08:00:04

This commit is contained in:
tactonbishop 2022-08-12 08:00:04 +01:00
parent d7f7fed26c
commit cd7199f738
29 changed files with 15 additions and 7 deletions

View file

@ -11,12 +11,10 @@ MongoDB is not a relational database system like SQL, instead it is document-bas
Most of the notes on Mongo will introduce it within the context of Node.js backend. We will be sending Javascript objects and arrays to Mongo and returning them as JSON.
## Databaases, collections, documents
## Databases, collections, documents
Although Mongo is not a relational database it has a structure that we can understand in relation to that paradigm. A **database** is obviously the overall structure. It comprises **collections** which are organised sets of data that are analagous to [tables](/Databases/Relational_database_architecture.md#table) in RDBs. Within each collection are a series of **documents** which we can think of as being equivalent to [rows](/Databases/Relational_database_architecture.md) in RDB table: units that comprise the collection.
A document is a container comprising key-value pairs in the manner of an object.
![](/img/mongo-db-structure.svg)
The quick brown fox jumps

View file

@ -102,8 +102,18 @@ This returns:
> Note that the UUID is always returned, whether we specify it or not.
## Comparison operators
## Filtering with operators
So far when filtering we have been doing so with reference to properties that exist on the document's model (`author`, `isPublished` etc) and we have applied tranformations on the data returned (sorting, limiting the number or matches etc.). However we can also apply **operators** within our queries. Operators allow us to perform computations on the data, for example: for a given numerical property on an object, return the objects for which this value is within a certain range.
When we apply operators we use the `$` symbol before the operator and pass the operator function as an object.
The schema:
```
Model.find( { property: { $operator: conditions } } )
```
### Comparison operators
The following comparison operators are available in MongoDB:
| Operator | Function |
@ -129,4 +139,4 @@ To filter course prices that are either 10, 15 or 20:
```js
Course.find(({price: {$in: [10, 15, 20] } }))
```
```

View file

@ -2,13 +2,13 @@
font-family: 'Inter';
} */
pre, code {
/* pre, code {
font-family: 'JetBrains Mono' !important;
}
code, code {
font-family: 'Jetbrains mono';
}
} */
/*
h1 {