CRUD Flashcards

1
Q

crud

A

stands for create read update and delete the data
an operation in data managements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

BSON

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

two documents don’t need to have the same schema
may one document has four fields and another one has
two

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

db.collectionName.deleteOne(filter, options)

A

this delete the first document that match with the filter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

db.collectionName.updateOne(filter, data, options)
db.collectionName.updateOne(filter, {$set: {key: value}})

A

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 :

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

db.collectionName.updateMany(filter, data, options)

A

update more than one document that matched with filter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

db.collectionName.deleteMany(filter, options)

A

delete every documents that matched with the filter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

db.collectionName.insertMany([data1, data2, …])

A

allows to insert many documents to collectionName of db

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

db.collectionName.find(filter)

A

find all documents that matched with filter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

do.collectionName.findOne(filter)

A

find the first element that matched with the filter
note: pretty not work in this method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

key: {$gt: value}

A

this is a filter for every documents that has greater value
for that key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

db.collectionName.replaceOne(filter, data, options)

A

replace the existing data with the new data if filter was matched

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

db.collectionName.update(filter, data, options)
deprecated

A

it do the same as replaceOne do but not update and not
like updateOne or Many

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

if the documents be more than 20

A

it doesn’t show the others it called cursor object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

db.collectionName.find().toArray()

A

shows all the documents in array even more than 20

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

projection

A

if you wana retrive some special fields of document, not entire document,
should use projection and it reduce usage of bandwith, for this use find(filter, {key: 1})
if you want to dont retrive id you must use _id: 0, in projecction section

17
Q

Projection ai explaination

A

In MongoDB, projection refers to the process of selecting only a subset of fields from a collection. When querying a MongoDB collection, you can specify which fields you want to retrieve using a projection. This can be useful when you only need certain pieces of data and don’t want to retrieve the entire document.

To project fields in MongoDB, you use the projection parameter when calling the find() method. For example, if you have a collection of documents representing products with fields such as name, price, and description, and you only want to retrieve the names of the products, you would use:

db.products.find({}, { name: 1 })
This query will retrieve all documents in the products collection, but only return the name field for each document. The 1 value in the projection indicates that the field should be included in the result, while a 0 value would indicate that the field should be excluded.

You can also use complex projections to include or exclude multiple fields, or to specify nested fields within embedded documents. The syntax for projections can be found in the MongoDB documentation.

18
Q

read essays on folder

A
19
Q

embedded documents or arrays

A

limited to 100 embedded docs
and has limited size below 16MB

20
Q

db.collectionName.find({“embedded.key”: “valu”})

A

returns all docs with filter of key of embedded document has vlue of vlue

21
Q

db.collectionName.find().embedded

A

return all embedded documents of all documents