It's all about the Data. In the Base. No treble.
How CRUD-y
Create, Read, Update, and Delete are the basic functions for a database.
Let’s start up a database instance and go through each of those operations!
Starting a database & Entering the MongoDB Shell
$ mkdir -p /mongodb/jamstack-db/
$ mongod --dbpath /mongodb/jamstack-db/
$ mongo
> use jamstack
switched to db jamstack
Adding Data https://docs.mongodb.com/getting-started/shell/insert/
> db.jamstack.insert(
{
"id" : "123456789",
"jam" : "strawberry",
"msrp" : "3"
}
)
WriteResult({ "nInserted" : 1 })
Viewing Data https://docs.mongodb.com/getting-started/shell/query/
> db.jamstack.find()
{ "_id" : ObjectId("5a276d5305198a11607abfaf"), "id" : "123456789", "jam" : "strawberry", "msrp" : "3" }
Updating Data https://docs.mongodb.com/getting-started/shell/update/
> db.jamstack.update(
{ "id" : "123456789" },
{
$set: { "msrp": "5" },
$currentDate: { "lastModified": true }
}
)
Removing Data https://docs.mongodb.com/getting-started/shell/remove/
> db.jamstack.remove( { "id": "123456789" } )
WriteResult({ "nRemoved" : 1 })
> db.jamstack.find()
>
Next Up
We’ll be writing an API in NodeJS to do these CRUD operations via HTTP. Stay tuned!