mongo db summary in nodejs |nodejs tutorials

 const {it}=require("node:test")


sudo apt-get install mongodb
sudo service mongodb start
mongo
show dbs

db - to find u r in which db
db.dropDatabase()

db.createCollection(name,coletion)
db.createCollection("employee",{size:524800,max:100,capped:true})

db.collectionnae.insert(document)
db.collectionnae.insertOne(document)

db.posts.insertOne({
title: "Post Title 1",
body: "Body of post.",
category: "News",
likes: 1,
tags: ["news", "events"],
date: Date()
})


db.posts.insertMany([
{
title: "Post Title 2",
body: "Body of post.",
category: "Event",
likes: 2,
tags: ["news", "events"],
date: Date()
},
{
title: "Post Title 3",
body: "Body of post.",
category: "Technology",
likes: 3,
tags: ["news", "events"],
date: Date()
},
{
title: "Post Title 4",
body: "Body of post.",
category: "Event",
likes: 4,
tags: ["news", "events"],
date: Date()
}
])


db.employee.find()

db.employee.find().pretty()

db.employee.find({age: {$lt: 15}},{city:1,name:1,age:1}).pretty();

db.posts.findOne() -matches first one


$lt
$gt
$set

update one row which is matched first
db.employee.update({age:3},{$set:{age:23}});
db.posts.updateOne( { title: "Post Title 1" }, { $set: { likes: 2 } } )

update it if not found insert it

db.posts.updateOne(
{ title: "Post Title 5" },
{
$set:
{
title: "Post Title 5",
body: "Body of post.",
category: "Event",
likes: 5,
tags: ["news", "events"],
date: Date()
}
},
{ upsert: true }
)


update alll rows matched
db.employee.updateMany({age:2},{$set:{age:5}});
db.employee.updateMany({city:"mumbai"},{$mul:{salary:1.02}});

delete


db.employee.remove({age:{$eq :20}})

db.employee.remove({})

db.posts.deleteOne({ title: "Post Title 5" })

db.posts.deleteMany({ category: "Technology" })

db.getCollectionNames()

query parameters

$eq: Values are equal
$ne: Values are not equal
$gt: Value is greater than another value
$gte: Value is greater than or equal to another value
$lt: Value is less than another value
$lte: Value is less than or equal to another value
$in: Value is matched within an array
Logical
The following operators can logically compare multiple queries.

$and: Returns documents where both queries match
$or: Returns documents where either query matches
$nor: Returns documents where both queries fail to match
$not: Returns documents where the query does not match
got errror

Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
g


dpkg -l | grep mongo 2065 sudo apt purge mongodbb 2066 sudo apt purge mongodb 2067 dpkg -l | grep mongodb 2068 sudo apt purge mongodb-clients 2069 dpkg -l | grep mongodb 2070 sudo apt purge mongodb-server-core 2071 sudo apt-get autoremove 2072 dpkg -l | grep mongodb 2073 sudo apt-get remove mongodb* --purge 2074 sudo apt-get purge mongodb-org* 2075 sudo rm -r /var/log/mongodb 2076 sudo rm -r /var/lib/mongodb 2077 sudo apt-get remove --purge mongodb 2078 sudo apt-get install mongodb 2079 sudo service mongodb start 2080 mongo


sudo wget https://downloads.mongodb.com/compass/mongodb-compass_1.14.1_amd64.deb
 1993  sudo dpkg -i mongodb-compass_1.14.1_amd64.deb
 1994  mongodb-compass

No comments:

Post a Comment

Event listening in react

 How we can listen to som eevents some envents fire like click or automatically user enters into input button , that is event on word type i...