MongoDB queries for CRUD operation


root@localhost student1]# systemctl start mongod
[root@localhost student1]# mongo
MongoDB shell version: 2.4.6
connecting to: test
> show dbs
TE    0.203125GB
company     0.203125GB
local 0.078125GB
tecomp      0.203125GB
> use shubhangi
switched to db shubhangi
> show collections
> db.createCollection("information")
{ "ok" : 1 }

> db.information.insert({"rollno":101,"name":"shubhangi","marks":85});
> db.information.insert({"rollno":102,"name":"Itisha","marks":90});
> db.information.insert({"rollno":103,"name":"ram","marks":88});
> db.iformation.find()

> db.information.find()
{ "_id" : ObjectId("59b8ba5dc1991a8ea9ff1dea"), "rollno" : 101, "name" : "shubhangi", "marks" : 85 }
{ "_id" : ObjectId("59b8bacbc1991a8ea9ff1deb"), "rollno" : 102, "name" : "Itisha", "marks" : 90 }
{ "_id" : ObjectId("59b8bae9c1991a8ea9ff1dec"), "rollno" : 103, "name" : "ram", "marks" : 88 }
> db.information.find().pretty()
{
      "_id" : ObjectId("59b8ba5dc1991a8ea9ff1dea"),
      "rollno" : 101,
      "name" : "shubhangi",
      "marks" : 85
}
{
      "_id" : ObjectId("59b8bacbc1991a8ea9ff1deb"),
      "rollno" : 102,
      "name" : "Itisha",
      "marks" : 90
}
{
      "_id" : ObjectId("59b8bae9c1991a8ea9ff1dec"),
      "rollno" : 103,
      "name" : "ram",
      "marks" : 88
}
> db.information.update({"marks":85},{$set :{"marks":87}})
> db.information.remove({"rollno":103})
> db.information.find()
{ "_id" : ObjectId("59b8ba5dc1991a8ea9ff1dea"), "rollno" : 101, "name" : "shubhangi", "marks" : 87 }
{ "_id" : ObjectId("59b8bacbc1991a8ea9ff1deb"), "rollno" : 102, "name" : "Itisha", "marks" : 90 }
> db.information.find().pretty()
{
      "_id" : ObjectId("59b8ba5dc1991a8ea9ff1dea"),
      "rollno" : 101,
      "name" : "shubhangi",
      "marks" : 87
}
{
      "_id" : ObjectId("59b8bacbc1991a8ea9ff1deb"),
      "rollno" : 102,
      "name" : "Itisha",
      "marks" : 90
}

 

Popular posts from this blog

DDL DML DCL and TCL

Implementation of Calculator using lex and yacc

A Register Allocation algorithm that translates the given code into one with a fixed number of registers.