Skip to content

Week 3 Homework - Beau Barth - w3-mongo#23

Open
bbarth86 wants to merge 3 commits intopce-uw-jscript400:masterfrom
bbarth86:master
Open

Week 3 Homework - Beau Barth - w3-mongo#23
bbarth86 wants to merge 3 commits intopce-uw-jscript400:masterfrom
bbarth86:master

Conversation

@bbarth86
Copy link

No description provided.


* **Your Answer:**

---A `document` represents a record/collection of data. In mongoDB, it is stored in BSON format, which is similar to JSON. A `collection` is a grouping of documents, usually grouped for a shared or similar purpose, like transactions, or pricing/inventory collections. A `database` contains both documents, invidiually or in collections.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A database will primarily contain collections as opposed to documents.


* **Your Answer:**

---It is used to establish a unique ID for each record. By default however, MongoDB (Mongoose? This was going to be checked/confirmed) will create a unique ID even if this statement is not present.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mongo sets the ID by default. With both Mongoose & MongoDB, you can disable this.


* **Your Answer:**

---You can resolve this issue by adding `useFindAndModify: true` to your mongoDB connection statement . If i am understanding the Mongoose documentation correctly, this statement is added in order to force Mongoose to use MongoDB driver's `findOneandUpdate()` function instead of MongoDB driver's `findAndModify()` function. Is that correct?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct!


* **Your Answer:**

---`Model.create()` failed to return a response, even though the creation of the document was successful in the DB. I am not entirely sure that i understand the error in the terminal, but it seems as though i am dealing with a promise rejection and would need to use something like `.catch()` to handle with an error message, function, etc. Is it because ``Model.create()` is not returning a query?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, Model.create() returns a different type of object so you can't call .select() on it.


* **Your Answer:**

--- I see the specific messaging coming back in the terminal, but i'm unclear on how to take the `message` key/value pair and parse it to my error message.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the error should have a messages key that is an array of all the errors that occurred. Looping through this will give you access to the individual messages.


* **Your Answer:**

--- So I consistently ran into the 400 error defined in my try/catch statements, but when checking Atlas I can see the document was created. My series.js file is also uploaded for reference. Why might this be? To answer the question however, the `_id` field was automatically created by Mongoose.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if you're still having this issue. I would try and log out the error your receiving in the catch portion to narrow this down.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants