Skip to content

Commit

Permalink
PSMDB-1411 Implemented new design, restructred docs (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
nastena1606 authored Feb 28, 2024
1 parent a280663 commit ea585f5
Show file tree
Hide file tree
Showing 32 changed files with 1,046 additions and 206 deletions.
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

2 changes: 1 addition & 1 deletion docs/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ You can use any of these authentication mechanisms supported in Percona Server f

* [SCRAM](#scram)(default)
* [x.509 certificate authentication](#x509-certificate-authentication)
* [LDAP authentication with SASL](#ldap-authentication-with-sasl))
* [LDAP authentication with SASL](#ldap-authentication-with-sasl)
* [Kerberos Authentication](#kerberos-authentication)
* [Authentication and authorization with direct binding to LDAP](authorization.md)
* [AWS IAM authentication](aws-iam.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/comparison.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Percona Server for MongoDB feature comparison

Percona Server for MongoDB 5.0 is based on [MongoDB 5.0](https://docs.mongodb.com/manual/introduction/). Percona Server for MongoDB extends MongoDB Community Edition to include the functionality that is otherwise only available in MongoDB Enterprise Edition.
Percona Server for MongoDB 5.0 is based on [MongoDB Community Edition 5.0](https://docs.mongodb.com/manual/introduction/) and extends it with the functionality that is otherwise only available in MongoDB Enterprise Edition.

| | PSMDB | MongoDB |
|------------------------| ------ | -------- |
Expand Down
101 changes: 101 additions & 0 deletions docs/connect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Connect to Percona Server for MongoDB

After you have successfully installed and started Percona Server for MongoDB, let's connect to it.

By default, access control is disabled in MongoDB. We recommend enabling it so that users must verify their identity to be able to connect to the database. Percona Server for MongoDB supports several [authentication methods](authentication.md). We will use the default one, [SCRAM](authentication.md#scram), to configure authentication.

The steps are the following:
{.power-number}

1. Connect to Percona Server for MongoDB instance without authentication:

```{.bash data-prompt="$"}
$ mongosh
```

??? example "Sample output"

```{.text .no-copy}
Current Mongosh Log ID: 6598270a3a0c418751550ded
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.0.0
Using MongoDB: {{release}}
Using Mongosh: 2.0.0
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
test>
```

2. Create the administrative user in the `admin` database:

1. Switch to the `admin` database

```{.javascript data-prompt=">"}
> use admin
```

??? example "Sample output"

```{.text .no-copy}
switched to db admin
```

2. Create the user:

```{.javascript data-prompt=">"}
> db.createUser(
{
user: "admin",
pwd: passwordPrompt(), // or cleartext password
roles: [
{ role: "userAdminAnyDatabase", db: "admin" },
{ role: "readWriteAnyDatabase", db: "admin" }
]
}
)
```
3. Shutdown the `mongod` instance and exit `mongosh`
``` {.bash data-prompt=">"}
> db.adminCommand( { shutdown: 1 } )
```
4. Enable authentication
=== ":octicons-file-code-24: Command line"
Start the server with authentication enabled using the following command:
``` {.bash data-prompt="$"}
$ mongod --auth --port 27017 --dbpath /var/lib/mongodb --fork --syslog
```
=== ":material-console: Configuration file"
1. Edit the configuration file
```yaml title="/etc/mongod.conf"
security:
authorization: enabled
```
2. Start the `mongod` service
``` {.bash data-prompt="$"}
$ systemctl start mongod
```
5. Connect to Percona Server for MongoDB and authenticate.
``` {.bash data-prompt="$"}
$ mongosh --port 27017 --authenticationDatabase \
"admin" -u "admin" -p
```
## Next steps
[Run simple queries :material-arrow-right:](crud.md){.md-button}
158 changes: 158 additions & 0 deletions docs/crud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
# Manipulate data in Percona Server for MongoDB

After you connected to Percona Server for MongoDB, let's insert some data and operate with it.

!!! note

To secure the data, you may wish to use [data-at-rest encryption](data-at-rest-encryption.md). Note that you can only enable it on an empty database. Otherwise you must clean up the data directory first.

See the following documentation for data-at-rest encryption:

* [Using HashiCorp Vault server](vault.md)
* [Using KMIP server](kmip.md)
* [Using a local keyfile](keyfile.md)

## Insert data {.power-number}

1. For example, let's add an item to the `fruits` collection. Use the `insertOne()` command for this purpose:

``` {.javascript data-prompt=">"}
> db.fruits.insertOne(
{item: "apple", qty: 50}
)
```

If there is no `fruits` collection in the database, it will be created during the command execution.

??? example "Sample output"

```{.json .no-copy}
{
acknowledged: true,
insertedId: ObjectId('659c2b846252bfad93fc1578')
}
```

2. Now, let's add more fruits to the `fruits` collection using the `insertMany()` command:
``` {.javascript data-prompt=">"}
> db.fruits.insertMany([
{item: "banana", weight: "kg", qty: 10 },
{item: "peach", weight: "kg", qty: 30}
])
```
??? example "Sample output"
```{.json .no-copy}
{
acknowledged: true,
insertedIds: {
'0': ObjectId('659c2bc46252bfad93fc1579'),
'1': ObjectId('659c2bc46252bfad93fc157a')
}
}
```
See [Insert documents](https://www.mongodb.com/docs/manual/tutorial/insert-documents/) for more information about data insertion.
## Query data
Run the following command to query data in MongoDB:
``` {.javascript data-prompt=">"}
> db.fruits.find()
```
??? example "Sample output"
```{.json .no-copy}
[
{ _id: ObjectId('659c2b846252bfad93fc1578'), item: 'apple', qty: 50 },
{
_id: ObjectId('659c2bc46252bfad93fc1579'),
item: 'banana',
weight: 'kg',
qty: 10
},
{
_id: ObjectId('659c2bc46252bfad93fc157a'),
item: 'peach',
weight: 'kg',
qty: 30
}
]
```
Refer to the [Query documents](https://www.mongodb.com/docs/manual/tutorial/query-documents/) documentation to for more information about reading data.
## Update data
Let's update the `apples` entry by adding weight to it.
{.power-number}

1. Use the `updateOne()` command for that:

```{.javascript data-prompt=">"}
> db.fruits.updateOne(
{"item": "apple" },
{$set: {"weight": "kg"}}
)
```

??? example "Sample output"

```{.json .no-copy}
{
acknowledged: true,
insertedId: null,
matchedCount: 1,
modifiedCount: 1,
upsertedCount: 0
}
```

2. Query the collection to check the updated document:

```{.javascript data-prompt=">"}
> db.fruits.find({item: "apple"})
```

??? example "Sample output"

```{.json .no-copy}
[
{
_id: ObjectId('659c2b846252bfad93fc1578'),
item: 'apple',
qty: 50,
weight: 'kg'
}
]
```

See [Update methods](https://www.mongodb.com/docs/manual/reference/update-methods/) documentation for other available data update methods

## Delete data

Run the following command to delete all documents where the quantity is less than 30 kg:

```{.javascript data-prompt=">"}
> db.fruits.deteleMany(
{"qty": {$lt: 30} }
)
```

??? example "Sample output"

```{.json .no-copy}
{ acknowledged: true, deletedCount: 1 }
```

Learn more about deleting data in [Delete methods](https://www.mongodb.com/docs/manual/reference/delete-methods/) documentation.

Congratulations! You have used basic create, read, update and delete (CRUD) operations to manipulate data in Percona Server for MongoDB. See [MongoDB CRUD Concepts](https://www.mongodb.com/docs/manual/core/crud/) manual to learn more about CRUD operations.

## Next steps

[What's next? :material-arrow-right:](what-next.md){.md-button}
Loading

0 comments on commit ea585f5

Please sign in to comment.