MongoDB Flashcards

1
Q

Intro to MongoDB

A

Install MongoDB on Mac

Follow directions on Mongodb

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

MongoDB CRUD Operations

A

Create
Create a database

terminal: use

Create a collection / Insert new items into a collection
db..insertOne()
db..insertMany()
If the collection doesn’t exist, then a new one will be created

Read / Query
terminal: show collections
Shows all the collections
db..find()
Displays all the data in the collection
db..find( , )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Query Examples

A

Displays all the data in the collection that meets the query criteria
Example of Query:
{name : “Pencil”}
{price: {$gt: 1}}
Example of Projection:
{name : 1, address: 1}
1 means true
0 means false
We can dictate which fields we want back from the query
So in this case, where the data has a name and an address

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

Update

A

db..updateOne(, )

The data to update

{$set: {: }}

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

Delete

A

db. .deleteOne()

db. .deleteMany()

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

Relationships

A
One to Many Relationships are great for NoSQL - MongoDB
Example:	
Product
Review 1
Review 2
Review 3 ...
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Mongo Shell

A
terminal: mongod
Starts up the mongo server
When you see “waiting for connections on port 27017” then the server has started
terminal: mongo
Starts up the mongo shell
Troubleshoot:
sudo killall -15 mongod
If unable to start up the server using mongod
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

MongoDB w/ Node JS

A

2 ways to incorporate MongoDB app with Node.js
1. Native MongoDB Driver
Install a MongoDB driver from the documentation
One that corresponds to the programming language
In this case, Node.js MongoDB driver
npm install mongodb
2. mongoose
ODM
Object Data Modeling library
Most popular package to work with MongoDB and Node.JS

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