MongoDB Flashcards

1
Q

The base of traditional relational database management systems:

A

Atomicity: All operations in a transactionsucceeds or rolled back.

Consistency: After a transaction completed, the database remains consistence.

Isolation: Transactions are executed without interfering with other transactions.

Durability: After a transaction completed, changes will be permanent.

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

Define NoSQL

A

No SQL is a generic term that refers to any non-relational data management system and does not use SQL query language.

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

MongoDB features:

A

Indexing
Aggregations
File Storage
Special collection types

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

Create a collection named “newCollection” and insert the field “field” and the value “value :

A

> db.newCollection.insertOne({“field” : “value”})

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

Create a database named “myNewDb”

A

> use myNewDb

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

Drop the current database

A

db.dropDatabase()

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

Add one document to the collection “TestKey” with an id of 1 and a name of “test2”

A

db.TestKey.insertOne({_id:1, Name: “test2”})

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

The command to insert multiple documents into a collection:

A

db.collection.insertMany([
{ // fields and values } ,
{ // fields and values }
])

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

display the “Employee” collection

A

db.Employee.find()
OR
db.Employee.find().pretty()

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

display all databases

A

show dbs

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

display collections of current database

A

show collections

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

show all the collections in an array:

A

db.getCollectionNames()

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

drop the collection “Dept”

A

db.Dept.drop()

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

create a collection named “Room”

A

db.createCollection(“Room”)

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

Remove all documents in the collection “foo”

A

db.foo.remove()

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

remove all documents from the mailing.list collection where the value “opt-out” equals “true”

A

db.mailing.list.remove({“opt-out” : true })

17
Q

Delete Documents for one and for many

A

db. collection.deleteOne({//fields and values})

db. collection.deleteMany()

18
Q

Update the documents in the collection “Course” that have the “NumOfHours” value as 48. Change the CourseName to “OOP 1”

A

db.Course.updateOne(
{NumOfHours : 48},
{$set : {CourseName : “OOP 1”}}
)

19
Q

Update multiple documents from the collection “Course” where NumOfHours is 48 and Program.Duration is 3 years. Set the CourseName to “System Design”

A

db.Course.updateMany(
{ $and : [ {NumOfHours: 48},
{Program.Duration : “3 years”} ] },
{$set : {CourseName: “System Design”}} )

20
Q
What are the comparison operators for :
<
<=
>
>=
!=
A
$lt
$lte
$gt
$gte
$ne
21
Q

Query employees who are between the ages of 25 and 40

A

db.Employee.find({age: {$gte: 25, $lte 40 }})

22
Q

Find the employees details who are earning less or equal to 2000

A

db.Employee.find({salary: {$lte : 2000}})

23
Q

Find all employees details who are not working HR department.

A

db.Employee.find({department: {$ne : “HR”}})

24
Q

find employees with a salary of either 1200, 2000, or 2500

A

db.Employee.find({salary: {$in : [1200, 2000, 2500] }})

25
Q

find employees that DON’T have a salary of either 1200, 2000, or 2500

A

db.Employee.find({salary: {$nin : [1200, 2000, 2500]}})

26
Q

Display the name of employees where the department name is not HR and the age is 55

A

db.Employee.find({department.name: {$ne : “HR”}, age: 55}, {name: 1})