To Start MongoDB ,
step-1: run "mongod" in a terminal,
step-2: run "mongosh" in a different terminal
to see database= show dbs
to create a database = use database-name
to switch to a database= use database-name
to create a collection= db.createCollection("collection-name")
to show collections= show collections
to delete a database = first go to that database and then type db.dropDatabase()
to see in which database you are = db
to insert a single document = db.collection_name.insertOne({name:"Apurbo Roy", age:
23})
to insert multiple document = db.collection_name.insertMany([{name:"Sakib",
age:23},{name:"Raju", age:20}])
to show all the data of a collection = db.collection_name.find()
to show all the data of a collection beautifully = db.users.find().pretty()
to show a specific data = db.users.find({name:"Sakib"}) //you can search by any
key of the object.
to show your desired number of search result =
db.collection_name.find({age:23}).limit(number)
to update a user data = db.collection_name.update({name:"Apurbo Roy"},{$set:
{age:35}}) //here age will be updated.
to delete a data = db.collection_name.deleteOne({name:"Apurbo Roy"}) //you can
delete by entering any value of the object.
to get data without defining schema,
const db = mongoose.connection;
const collection = db.collection("project_data");
const projectData = await collection.find({}).toArray();
in mongodb, collection name must be plural