CRUD Operations in MongoDB
CRUD Operations in MongoDB
CRUD Operations in MongoDB
CRUD Operations
in MongoDB
@nacercodes
001
Insert One
db.collection.insertOne(document)
db.languages.insertOne({
name: 'Python',
appearedIn: 1991,
isNew: false
})
@nacercodes
002
Insert Many
db.collection.insertMany([
document1,
document2,
...
])
db.languages.insertMany([
{ name: 'Python' },
{ name: 'JavaScript' }
])
@nacercodes
003
Find One
db.collection.findOne(query, projection)
db.languages.findOne(
{ name: 'Python' },
{ createdBy: 1 }
@nacercodes
004
Find
db.collection.find(query, projection)
db.languages.find(
{ name: 1 }
Gets only the _id and name fields of all the documents
that satisfy the search criteria (appearedIn greater
than “1990”).
Calling find() with no arguments will return all the
documents.
@nacercodes
005
Update One
db.collection.updateOne(filter, update)
db.languages.updateOne(
{ name: 'Go' },
@nacercodes
006
Update Many
db.collection.updateMany(filter, update)
db.languages.updateMany(
@nacercodes
007
Delete One
db.collection.deleteOne(filter)
db.languages.deleteOne({
})
@nacercodes
008
Delete Many
db.collection.deleteMany(filter)
db.languages.deleteMany({
})
@nacercodes
Nacer Codes
@nacercodes