MongoDB Module #56 Flashcards
What does Mongo store instead of tables?
Documents, but really they’re objects as in JavaScript objects…like JSON but enhanced.
How do you install Mongo locally using a Mac?
brew tap mongodb/brew
brew install mongodb-community
What is a collection in MongoDB
It is a collection of data that is the equivalent of a table in SQL.
Using the db.createCollection( ) command, what are the two arguments that can be passed?
The first arg is collection name, and the second is options.
What does the show databases command tell you?
Shows the DB size, config, name, basic info about the database.
How would you grab quick info from the command-line about collections?
Show collections for basic info about the collections in a MongoDB.
What method can be called to insert a new object?
Surprise! insert( ) for example:
db.dogs.insert( { name: “Roger” ) }
How can you get a look at what objects are in a collection
By calling the find( ) method. Example below:
db.dogs.find( ) returns something like
{ “_id” : ObjectID(“%bdc05df905df903bfe88269f5d”),
“name”: “Roger”
How does MongoDB keep track of documents in the database?
By assigning an ObjectID
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.
Call the findOne( ) method.
Say you want to update a document, how can we do that?
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 can we remove a record?
Call the remove( ) method Example below:
db.dogs.remove( { name: ‘Togo2”} )
which returns a confirmation like WriteResult( { “nRemoved” : 1 })
How can you remove all of the entries from a collection?
Pass an empty object like so:
db.dogs.remove({ })