0% found this document useful (0 votes)
43 views

Operation Select Database Insert Record

The document provides information about various MongoDB commands and how they compare to SQL commands. It discusses concepts like databases, collections, documents, embedded documents, operators, aggregation, sorting, updating, deleting and more. Examples are given for inserting, finding, updating and deleting documents as well as counting, projecting, filtering and ordering operations.
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Operation Select Database Insert Record

The document provides information about various MongoDB commands and how they compare to SQL commands. It discusses concepts like databases, collections, documents, embedded documents, operators, aggregation, sorting, updating, deleting and more. Examples are given for inserting, finding, updating and deleting documents as well as counting, projecting, filtering and ordering operations.
Copyright
© © All Rights Reserved
Available Formats
Download as XLSX, PDF, TXT or read online on Scribd
You are on page 1/ 11

OPERATION

SELECT DATABASE

INSERT RECORD

SELECT

WHERE CONDITION

> , < , >= < <=

And | Or

In

count()

ORDER BY

UPDATE
DELETE

DROP

TOP

DISTINCT

EMBEDED DOCUMENT AND DOT NOTATION : DOCUMENT WITHIN DOCUMENT AND TO ACCES THAT WE USE .
db.Employee.insert
(
{
Name:{FirstName:"Santosh",LastName:"Alex"},Age:37,Email:"[email protected]",Address:"USSR",Interest:
}
)

db.Employee.insert
(
{
Name:{FirstName:"Alex",LastName:"Smith"},Age:37,Email:"[email protected]",Address:"USSR",Interest:["D
}
)

db.Employee.find({"Name.FirstName":"Santosh"})

Mongodb is Schema Less ??? : No any predefined stru , Any document can contain any values

Mongodb follows: JSON format


1. Array :[ ]
2. Dictionaries : Associated Maps {Key:Value}

$exists : Will check for the particular fields


$type : Will check the data type
db.Employee.find({Name:{$type:2}})
TABLE : STUDENT (ID,NAME,MAILID,MOBILENO,CITY)

MONGODB COMMANDS VS SQL SERVER |ORACLE COMMAND

SQL SERVER

USE TEST

INSERT INTO STUDENT VALUES(1,'AAA','[email protected]',


9292929','LONDON')

SELECT ALL COLUMS


SELECT * FROM STUDENT

SELECT FEW COLUMNS


SELECT _ID,NAME,MOBILNO FROM STUDENT

SELECT * FROM STUDENT WHERE NAME='santosh'

SELECT * FROM STUDENT WHERE ID>2

SELECT * FROM STUDENT WHERE ID>=2

SELECT * FROM STUDENT WHERE ID<2

SELECT * FROM STUDENT WHERE NAME='santosh'


and mobile=234423

SELECT * FROM STUDENT WHERE NAME='santosh'


or mobile=234423

SELECT * FROM STUDENT WHERE _ID in(1,2,3)

select count(*) from student

SELECT * FROM STUDENT ORDER BY NAME

UPDATE STUDENT SET MOBILE=929282,Address='NewYork'


where id=1
DELETE FROM STUDENT WHERE ID=1

DELETE FROM STUDENT

DROP TABLE STUDENT

SELECT TOP 2 * FROM STUDENT

SELECT DISTINC NAME FROM STUDENT

$in, $all , $nin

db.Employee.insert
(
{
Name:'Robin',Age:27,Email:"[email protected]",Address:"Delhi",Interest:["Cooking","Music"]
}
)

db.Employee.insert
(
{
Name:'Jone',Age:57,Email:"[email protected]",Address:"Boston",Interest:["Driving","Music"]
}
)

db.Employee.insert
(
{
Name:'Allen',Age:37,Email:"[email protected]",Address:"USSR",Interest:["Driving","Music"]
}
)

CUMENT AND DOT NOTATION : DOCUMENT WITHIN DOCUMENT AND TO ACCES THAT WE USE .
db.Employee.insert

Name:{FirstName:"Santosh",LastName:"Alex"},Age:37,Email:"[email protected]",Address:"USSR",Interest:["Driving","Music"]

db.Employee.insert

Name:{FirstName:"Alex",LastName:"Smith"},Age:37,Email:"[email protected]",Address:"USSR",Interest:["Driving","Music"]

db.Employee.find({"Name.FirstName":"Santosh"})

hema Less ??? : No any predefined stru , Any document can contain any values

db.Employee.insert
(
{
Name:{FirstName:"Santosh",LastName:"Alex"},Age:37,Email:"[email protected]",Address:"USSR",Interest:["Driving","Music"]
}
)

db.Employee.insert
(
{
Name:{FirstName:"Alex",LastName:"Smith"},Age:37,Email:"[email protected]",Address:"USSR",Interest:["Driving","Music"]
}
)

db.Employee.insert
(
{
Name:"Scott",Salary:"5000"
}
)

ws: JSON format


1. Array :[ ]
2. Dictionaries : Associated Maps {Key:Value}

$exists : Will check for the particular fields


//$exists
db.Employee.find({Salary : { $exists : true }})
$type : Will check the data type
db.Employee.find({Name:{$type:2}})

String : 2
Double : 1
Embeded : 3
Date : 9
Null : 10
Boolean : 8
Regular Expression : 11
Array : 4
MONGODB

USE TEST

db.student.insert
(
{"_id":1,"Name":"santosh","Email":"[email protected]","mobile":"9626262","Address":"London"}
)

db.student.find()

db.student.find({},{"Name":1})
db.student.find({},{"Name":1,"mobile":true,"_id":0}) (1 : Has to display , 0 : Hide )

db.student.find({Name:"santosh"})

db.student.find({_id:{$gt:2}})

db.student.find({_id:{$gte:2}})

db.student.find({_id:{$lt:2}})

db.student.find({$and :[{Name:"santosh"},{mobile:'9626262'}]})

db.student.find({$or :[{Name:"santosh"},{mobile:'9626262'}]})

db.student.find({_id:{$in:[1,2,3]}})

db.student.find().count()

db.student.find().sort({Name:1}) (Ascending)
db.student.find().sort({Name:-1}) (Descending)

db.student.update({_id:1},{$set :{mobile:'73737',Address:'USA'}})

UPSERT (UPDATE + INSERT) (IF ID IS THERE ..WILL UPDATE OTHERWISE GO FOR INSERT)
db.student.update({_id:1},{$set :{mobile:'73737',Address:'USA'}},{upsert:true})

MULTI (WILL GO FOR MULTIPLE DOCUMENT UPDATE, BY DEFAULT ONLY ONE DOC WILL UPDATED)

db.student.update({_id:1},{$set :{mobile:'73737',Address:'USA'}},{multi:true})

db.student.remove({_id:1})

db.student.remove({})

db.student.drop()

LIMIT
db.student.find().limit(2)

SKIP
db.student.find().skip(2).limit(2)

db.student.distinct("name)

db.Employee.find({Interest: {$in :["Driving","Cooking"]}})

db.Employee.find({Interest: {$all :["Driving","Music"]}})

db.Employee.find({Interest: {$nin :["Driving"]}})


erest:["Driving","Music"]

est:["Driving","Music"]

",Interest:["Driving","Music"]

nterest:["Driving","Music"]

You might also like