The ObjectId type is used to create primary/foreign key relationships between objects in the database. While this property looks like a String, it’s actually an object with a unique reference. Scott explains how to use the ObjectId type and answers a number of audience questions about it.
- And here's the interesting part,…as far as relationships go.…If you're a SQL person, a relational database person,…you'll probably be like,…"Oh yeah, it's not really relations,"…but this is how it works in Mongoose.…What we can do is if we want to set up relationships…between two models, we can disassociate the ID,…just like you would in any other database.…It's just how it works.…So, in Mongoose, the way it works is…we give it the type of ObjectId.…ObjectId is IDs.…
They are IDs in Mongoose.…They're just called ObjectIds.…So if we say, oh yeah, we want the dog to have one owner.…So its type is mongoose.Schema.Types.ObjectId.…It looks like a string of an ID…when you get it back from the database,…but it's not.…It's actually an object.…It converts it to a string…and I want to reference the owner schema.…So there exists in this database somewhere…another model called owner.…So if there's a string here,…I'm telling Mongoose that that ID is referencing…some owner somewhere and then it's required.…
So you can't save a dog without an owner.…
This course was created by Frontend Masters. It was originally released on 12/30/2015. We're pleased to host this training in our library.
- Executing Node.js
- Using Express
- What is middleware?
- Testing in Node.js
- Using Mongo with Node.js
- Data modeling
- Querying data with Mongoose
- Identifying sensitive routes
- Configuring the deployment
Skill Level Intermediate
Node.js: Build Your First Microservicewith Daniel Khan2h 9m Intermediate
Building APIs Using Hapi in Node.jswith Kirsten Hunter2h 23m Intermediate
Node.js: Extend and Maintain Applicationswith Daniel Khan3h 35m Intermediate
2. REST APIs
5. Organization and Configuration
7. Data Modeling
10. Securing Routes
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.