-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PSMDB-1411 Implemented new design, restructred docs (#815)
- Loading branch information
1 parent
a280663
commit ea585f5
Showing
32 changed files
with
1,046 additions
and
206 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
Oops, something went wrong.