Skip to content

Commit

Permalink
Add documentation for older versions (#3834)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi authored Dec 11, 2023
1 parent 62062ba commit 008b88e
Show file tree
Hide file tree
Showing 156 changed files with 16,935 additions and 40 deletions.
33 changes: 17 additions & 16 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,20 @@ services:
ports:
- 3000:3000
volumes:
- ./website/docs:/workdir/docusaurus-docs/docs:ro
# shared with blog
- ./website/babel.config.js:/workdir/docusaurus-docs/babel.config.js:ro
- ./website/sidebars.js:/workdir/docusaurus-docs/sidebars.js:ro
- ./website/src:/workdir/docusaurus-docs/src:ro
- ./website/static:/workdir/docusaurus-docs/static:ro
- ./website/src/components:/workdir/docusaurus-docs/src/components:ro
- ./website/src/css:/workdir/docusaurus-docs/src/css:ro

# We copy intro.js to redirect from /intro (old default docs page) to the root docs page.
- ./website/src/pages/intro.js:/workdir/docusaurus-docs/src/pages/intro.js
- ./website/build:/workdir/docusaurus-docs/build:rw

- ./website/babel.config.js:/workdir/docusaurus-docs/babel.config.js:ro
# docs sources
- ./website/docs:/workdir/docusaurus-docs/docs:rw
- ./website/docusaurus.config.js:/workdir/docusaurus-docs/docusaurus.config.js:ro
- ./website/sidebars.js:/workdir/docusaurus-docs/sidebars.js:ro
- ./website/versioned_docs:/workdir/docusaurus-docs/versioned_docs:rw
- ./website/versioned_sidebars:/workdir/docusaurus-docs/versioned_sidebars:rw
- ./website/versions.json:/workdir/docusaurus-docs/versions.json:rw

- ./website/build:/workdir/docusaurus-docs/build:rw
docusaurus-blog:
build:
context: ./build/deps
Expand All @@ -207,17 +208,17 @@ services:
ports:
- 3001:3001
volumes:
- ./website/blog:/workdir/docusaurus-docs/blog:ro
- ./website/static:/workdir/docusaurus-docs/static:ro
- ./website/src/components:/workdir/docusaurus-docs/src/components:ro
- ./website/src/css:/workdir/docusaurus-docs/src/css:ro

# shared with docs
- ./website/babel.config.js:/workdir/docusaurus-docs/babel.config.js:ro
- ./website/docusaurus.config-blog.js:/workdir/docusaurus-docs/docusaurus.config.js:ro
- ./website/sidebars.js:/workdir/docusaurus-docs/sidebars.js:ro

- ./website/src:/workdir/docusaurus-docs/src:ro
- ./website/static:/workdir/docusaurus-docs/static:ro
- ./website/build:/workdir/docusaurus-docs/build:rw

# blog sources
- ./website/blog:/workdir/docusaurus-docs/blog:ro
- ./website/docusaurus.config-blog.js:/workdir/docusaurus-docs/docusaurus.config.js:ro

networks:
default:
name: ferretdb
9 changes: 4 additions & 5 deletions website/docusaurus.config-blog.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ const config = {
srcDark: 'img/logo-light.png'
},
items: [
{
to: '/',
label: 'Blog',
position: 'left'
},
{
href: 'https://docs.ferretdb.io/',
position: 'right',
Expand Down Expand Up @@ -167,6 +162,10 @@ const config = {
label: 'FerretDB.com',
position: 'right',
},
{
label: 'Blog',
to: '/',
},
{
label: 'GitHub',
href: 'https://github.com/FerretDB/',
Expand Down
12 changes: 6 additions & 6 deletions website/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ const config = {
sidebarPath: require.resolve('./sidebars.js'),
editUrl: 'https://github.com/FerretDB/FerretDB/tree/main/website',

// versions: {
// // the latest minus one minor
// 'v1.15': {
// banner: 'none',
// },
// },
versions: {
// the latest minus one minor
'v1.15': {
banner: 'none',
},
},
},
theme: {
customCss: require.resolve('./src/css/custom.css'),
Expand Down
6 changes: 0 additions & 6 deletions website/src/pages/intro.js

This file was deleted.

7 changes: 0 additions & 7 deletions website/src/pages/markdown-page.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
label: Aggregation Operations
position: 6
link:
type: generated-index
slug: /aggregation-operations/
description: >
This section details aggregation operations in FerretDB, including aggregation commands, stages, and operators
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
sidebar_position: 1
---

# Aggregation pipeline and commands

Aggregation operations involve performing various operations on a large number of data records, such as data grouping, sorting, restructuring, or modifying.
These operations pass through one or more stages, which make up a pipeline.

![aggregation stages](/img/docs/aggregation-stages.jpg)

Each stage acts upon the returned documents of the previous stage, starting with the input documents.
As shown above, the documents pass through the pipeline with the result of the previous stage acting as input for the next stage, going from `$match` => `$group` => `$sort` stage.

For example, insert the following documents in a `sales` collection:

```js
db.sales.insertMany([
{ _id: 1, category: 'Electronics', price: 1000 },
{ _id: 2, category: 'Electronics', price: 800 },
{ _id: 3, category: 'Clothing', price: 30 },
{ _id: 4, category: 'Clothing', price: 50 },
{ _id: 5, category: 'Home', price: 1500 },
{ _id: 6, category: 'Home', price: 1200 },
{ _id: 7, category: 'Books', price: 20 },
{ _id: 8, category: 'Books', price: 40 }
])
```

A typical aggregation pipeline would look like this:

```js
db.sales.aggregate([
{ $match: { category: { $ne: 'Electronics' } } },
{
$group: {
_id: '$category',
totalPrice: { $sum: '$price' },
productCount: { $sum: 1 }
}
},
{ $sort: { totalPrice: -1 } }
])
```

In the pipeline, the complex query is broken down into separate stages where the record goes through a series of transformations until it finally produces the desired result.
First, the `$match` stage filters out all documents where the `category` field is not `Electronics`.
Then, the `$group` stage groups the documents by their `category` and calculates the total price and product count for each of those category.
Finally, the `$sort` stage sorts the documents by the `totalPrice` field in descending order.

So the above aggregation pipeline operation would return the following result:

```json5
[
{ _id: 'Home', totalPrice: 2700, productCount: 2 },
{ _id: 'Clothing', totalPrice: 80, productCount: 2 },
{ _id: 'Books', totalPrice: 60, productCount: 2 }
]
```

This section of the documentation will focus on [`aggregate` command](#aggregate-command), [aggregation stages](aggregation-stages.md), and aggregation operators.

## `aggregate` command

The aggregation command `aggregate` is a top-level command used for aggregating data across various pipeline stages.

The command is used for performing aggregation operations on a collection and lets you specify aggregation operations in a pipeline consisting of one or more stages and operators for transforming and analyzing data, such as grouping, filtering, sorting, projecting, and calculating aggregates.

```js
// Aggregation pipeline to perform aggregation operations on a collection
db.collection.aggregate([
// Stage 1: Matching documents based on a specific field and value
{ $match: { field: value } },
// Stage 2: Grouping documents by the "category" field and calculating the sum of the "quantity" field
{ $group: { _id: '$category', total: { $sum: '$quantity' } } }
])
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
sidebar_position: 2
---

# Aggregation stages

Aggregation stages are a series of one or more processes in a pipeline that acts upon the returned result of the previous stage, starting with the input documents.

| Supported aggregation stages | Description |
| ---------------------------- | ----------------------------------------------------------------------------------------------------- |
| `$count` | Returns the count of all matched documents in a specified query |
| `$group` | Groups documents based on specific value or expression and returns a single document for each group |
| `$limit` | Limits specific documents and passes the rest to the next stage |
| `$match` | Acts as a `find` operation by only returning documents that match a specified query to the next stage |
| `$project` | Specifies the fields in a document to pass to the next stage in the pipeline |
| `$skip` | Skips a specified `n` number of documents and passes the rest to the next stage |
| `$sort` | Sorts and returns all the documents based on a specified order |
| `$unset` | Specifies the fields to be removed/excluded from a document |
| `$unwind` | Deconstructs and returns a document for every element in an array field |
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
label: Basic CRUD Operations
position: 4
link:
type: generated-index
slug: /basic-operations/
description: >
Perform basic CRUD operations using FerretDB
80 changes: 80 additions & 0 deletions website/versioned_docs/version-v1.14/basic-operations/create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
sidebar_position: 2
---

# Insert operation

The insert operation adds a new document to a collection.

## Insert a single document

The `insertOne()` command is used to add a single document into a collection, using this syntax format:

```js
db.collection.insertOne({field1: value1, field2: value2,.... fieldN: valueN})
```

The example below depicts how a single document can be added to a collection.
If a collection does not exist, the insert command automatically creates one.

```js
db.scientists.insertOne({
name: {
firstname: 'Thomas',
lastname: 'Edison'
},
born: 1847,
invention: 'lightbulb'
})
```

If the operation is successful, you will get a response with acknowledged set to true, and the autogenerated ObjectId of the document that looks like this:

```js
{
acknowledged: true,
insertedId: ObjectId("6346fcafd7a4a1b0b38eb2db")
}
```

## Insert multiple documents at once

A collection can contain multiple documents.
Using the `insertMany()` command, you can add multiple documents to a collection at once.

```js
db.collection_name.insertMany([{ document1 }, { document2 }, ...{ documentN }])
```

The following example shows how to insert multiple documents into a collection:

```js
db.scientists.insertMany([
{
name: {
firstname: 'Alan',
lastname: 'Turing'
},
born: 1912,
invention: 'Turing Machine'
},
{
name: {
firstname: 'Graham',
lastname: 'Bell'
},
born: 1847,
invention: 'telephone'
},
{
name: {
firstname: 'Ada',
lastname: 'Lovelace'
},
born: 1815,
invention: 'computer programming'
}
])
```

You can retrieve all the documents in the collection with this command: `db.scientists.find({})`
88 changes: 88 additions & 0 deletions website/versioned_docs/version-v1.14/basic-operations/delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
sidebar_position: 5
---

# Delete operation

The delete operation removes a document from the database when a given query is met.
Two methods for deleting documents in a collection include `deleteOne()` and `deleteMany()`.

## Delete a single document

The `deleteOne()` method removes a single document (the first document that matches the query parameter) completely from the collection.

```js
db.collection.deleteOne({<query_params>})
```

Insert the following list of documents:

```js
db.scientists.insertMany([
{
firstname: 'Thomas',
lastname: 'Edison',
born: 1847,
invention: 'LightBulb',
nobel: true
},
{
firstname: 'Graham',
lastname: 'Bell',
born: 1847,
invention: 'telephone',
nobel: false
},
{
firstname: 'Nikola',
lastname: 'Tesla',
born: 1856,
invention: 'Tesla coil',
nobel: false
},
{
firstname: 'Ada',
lastname: 'Lovelace',
born: 1815,
invention: 'Computer programming',
nobel: false
}
])
```

This operation returns a response showing `acknowledged` as `true` and the `ObjectId` of the four inserted documents:

```js
{
acknowledged: true,
insertedIds: {
'0': ObjectId("63470121d7a4a1b0b38eb2df"),
'1': ObjectId("63470121d7a4a1b0b38eb2e0"),
'2': ObjectId("63470121d7a4a1b0b38eb2e1"),
'3': ObjectId("63470121d7a4a1b0b38eb2e2")
}
}
```

Next, delete a document from the collection where the field `nobel` is set to false.

```js
db.scientists.deleteOne({ nobel: false })
```

This operation returns a response that shows that a single document was deleted from the collection.

```js
{ acknowledged: true, deletedCount: 1 }
```

## Deletes multiple documents

To delete multiple documents at once, use the `deleteMany()` method.
Using the same record from earlier, let's delete all the documents with `nobel` set to false.

```js
db.scientists.deleteMany({ nobel: false })
```

This command removes all the documents in the collection that matches the query.
Loading

0 comments on commit 008b88e

Please sign in to comment.