MongoDB Module #56 Flashcards

1
Q

What does Mongo store instead of tables?

A

Documents, but really they’re objects as in JavaScript objects…like JSON but enhanced.

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

How do you install Mongo locally using a Mac?

A

brew tap mongodb/brew

brew install mongodb-community

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

What is a collection in MongoDB

A

It is a collection of data that is the equivalent of a table in SQL.

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

Using the db.createCollection( ) command, what are the two arguments that can be passed?

A

The first arg is collection name, and the second is options.

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

What does the show databases command tell you?

A

Shows the DB size, config, name, basic info about the database.

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

How would you grab quick info from the command-line about collections?

A

Show collections for basic info about the collections in a MongoDB.

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

What method can be called to insert a new object?

A

Surprise! insert( ) for example:

db.dogs.insert( { name: “Roger” ) }

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

How can you get a look at what objects are in a collection

A

By calling the find( ) method. Example below:

db.dogs.find( ) returns something like
{ “_id” : ObjectID(“%bdc05df905df903bfe88269f5d”),
“name”: “Roger”

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

How does MongoDB keep track of documents in the database?

A

By assigning an ObjectID

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

The find method is great, but that can potentially return a lot of data you don’t necessarily want to see. How can you be more specific in your search.

A

Call the findOne( ) method.

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

Say you want to update a document, how can we do that?

A

By calling the update( ) method on the collection of your choice. Such as the example below.

db. dogs.findOne( [name: ‘Togo’ } ) //finds the one you want to modify
db. dogs.update( {name: ‘Togo’}, {name: ‘Togo2’} ) Which simply renames the dog object.

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

How can we remove a record?

A

Call the remove( ) method Example below:

db.dogs.remove( { name: ‘Togo2”} )
which returns a confirmation like WriteResult( { “nRemoved” : 1 })

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

How can you remove all of the entries from a collection?

A

Pass an empty object like so:

db.dogs.remove({ })

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