Skip to content
Snippets Groups Projects
Commit f2915b6b authored by Andreas Kunz's avatar Andreas Kunz
Browse files

Add mongosh guide doc

parent 767f0662
Branches main
No related tags found
No related merge requests found
# Basic knowledge for using the MongoDB Shell
The documentation how to use the MongoDB Shell is found here: https://www.mongodb.com/docs/mongodb-shell/run-commands/
It is recommended to make active use of this documentation.
## Easy step by step guide
Run and try to understand the following commands:
```javascript
use products // switches to db products (creates one if not existent)
// insert one document
db.test.insertOne({"name" : "OST"})
// insert many documents
db.fakestore.insertMany([
{
"id": 1,
"title": "Fjallraven - Foldsack No. 1 Backpack, Fits 15 Laptops",
"price": 109.95,
"description": "Your perfect pack for everyday use and walks in the forest. Stash your laptop (up to 15 inches) in the padded sleeve, your everyday",
"category": "men's clothing",
"image": "https://fakestoreapi.com/img/81fPKd-2AYL._AC_SL1500_.jpg",
"rating": {
"rate": 3.9,
"count": 120
}
},
{
"id": 2,
"title": "Mens Casual Premium Slim Fit T-Shirts ",
"price": 22.3,
"description": "Slim-fitting style, contrast raglan long sleeve, three-button henley placket, light weight & soft fabric for breathable and comfortable wearing. And Solid stitched shirts with round neck made for durability and a great fit for casual fashion wear and diehard baseball fans. The Henley style round neckline includes a three-button placket.",
"category": "men's clothing",
"image": "https://fakestoreapi.com/img/71-3HjGNDUL._AC_SY879._SX._UX._SY._UY_.jpg",
"rating": {
"rate": 4.1,
"count": 259
}
}
])
// find documents with a field "price" with value 22.3
db.fakestore.find({"price" : 22.3})
// find documents with a field "category" with value "men's clothing" and a field "price" with a value greater than 20.0
db.fakestore.find({"category":"men's clothing", "price" : {$gt: 20.0}})
// update the price of the "Mens Casual Premium Slim Fit T-Shirts"
db.fakestore.updateOne( {"title": "Mens Casual Premium Slim Fit T-Shirts "},
{
$set: {
"price": 25.5
}
// delete all documents that have a field "price" with value 109.95
db.fakestore.deleteMany({"price" : 109.95})
```
## Notes
The example data used above belongs to https://fakestoreapi.com/.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment