CRUD Flashcards

1
Q

How do you add a document into a collection?

A

db.collection_name.insertOne({obj});

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

How do you add multiple documents in a collection?

A

db.collection_name.insertMany([{obj}, {obj}]);

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

How do you query for a document or documents?

A

db.collection_name.find({attr: val});

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

How do you do an AND query?

A

db.collection_name.find({attr: val, attr: val});

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

How do you do an OR query?

A

db.collection_name.find({$or: [{attr: val}, {attr: val}]});

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

How do you do a query containing less than or greater than parameters?

A

db.collection_name.find({attr: {$param: val}});

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

Name the parameters for comparisons in MongoDB?

A

lte => less than or equal to, lt => less than, gt => greater than, gte => greater than or equal to

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

How do you return only specific attributes for a document in a query?

A

db.collection_name.find({query}, {attr: 1, attr: 1});

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

How do you update a single document?

A

db.collection_name.updateOne({find_query}, {obj_to_update});

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

How do you update multiple documents?

A

db.collection_name.updateMany({find_query}, {obj_to_update});

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

How do you replace a document(s)?

A

db.collection_name.replaceOne/Many({find_query}, {obj_to_update});

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

How do you delete a document(s)?

A

db.collection_name.deleteOne/Many({find_query});

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