MongoDB is a cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas. MongoDB is developed by MongoDB Inc. and licensed under the Server Side Public License (SSPL).[1]
Establish a MongoDB environment using one of the following:
Docker Playground is a free online Docker environment. It requires no installation or configuration.
docker run -d --name=mongo-server mongo
docker exec -it mongo-server bash
mongosh
You can use your own Docker environment to run MongoDB.
docker run -d --name=mongo-server mongo
docker exec -it mongo-server bash
mongosh
Install MongoDB on your own system.
mongosh
use temperature
db.countries.insertMany( [
{ country: "Bulgaria", temperature: "45.2 °C" },
{ country: "Canada", temperature: "45 °C" },
{ country: "Federated States of Micronesia", temperature: "36.1 °C" },
{ country: "Finland", temperature: "37.2 °C" },
{ country: "Germany", temperature: "40.3 °C" },
{ country: "Japan", temperature: "41 °C" },
{ country: "Marshall Islands", temperature: "35.6 °C" },
{ country: "Palau", temperature: "35 °C" },
{ country: "Turkmenistan", temperature: "50.1 °C" },
] );
show databases
show collections
db.countries.find()
db.countries.insertOne( { country: "United States of America", temperature: "56.7 °C" } )
db.countries.find( {country: "United States of America"} )
db.countries.update(
{ country: "United States of America" },
{ $set: { temperature: "56.5 °C" } }
)
db.countries.find( {country: "United States of America"} )
db.countries.remove( { country: "United States of America" } )
db.countries.find()
db.countries.remove({})
db.countries.find()
show collections
db.countries.drop()
show collections
show databases
db.dropDatabase()
show databases