CRUD Flashcards
crud
stands for create read update and delete the data
an operation in data managements
BSON
data format used in mongodb. it is binary-encoded
of json and extends this
one example is that objectId used in mongodb but this format is not legal in json data
two documents don’t need to have the same schema
may one document has four fields and another one has
two
db.collectionName.deleteOne(filter, options)
this delete the first document that match with the filter
db.collectionName.updateOne(filter, data, options)
db.collectionName.updateOne(filter, {$set: {key: value}})
it updates the first document in the collectionName
that matched with the filter and it add or replace with data
to do this you should use $set with :
db.collectionName.updateMany(filter, data, options)
update more than one document that matched with filter
db.collectionName.deleteMany(filter, options)
delete every documents that matched with the filter
db.collectionName.insertMany([data1, data2, …])
allows to insert many documents to collectionName of db
db.collectionName.find(filter)
find all documents that matched with filter
do.collectionName.findOne(filter)
find the first element that matched with the filter
note: pretty not work in this method
key: {$gt: value}
this is a filter for every documents that has greater value
for that key
db.collectionName.replaceOne(filter, data, options)
replace the existing data with the new data if filter was matched
db.collectionName.update(filter, data, options)
deprecated
it do the same as replaceOne do but not update and not
like updateOne or Many
if the documents be more than 20
it doesn’t show the others it called cursor object
db.collectionName.find().toArray()
shows all the documents in array even more than 20