Learn how to create a unique field in the collection. Learn about both the creation of a unique index and the use of the _id field to impose uniqueness.
- [Instructor] When working with a database,…frequently you need to be able…to impose constraints on the data.…The most common use case is requiring…that a particular field be unique across the collection.…The underscore ID field can be set…when the document is inserted,…but in many cases, you'll want to be able…to impose this kind of restriction on other fields.…I'll go over how to create a unique index,…and how you would use underscore ID with your own values.…Make sure your Mongo server is running,…and in a separate window,…start up the Mongo Client and Use Learning Mongo.…
The first thing we need to do is drop all the items…from the Tours collection.…Those items weren't created with a unique constraint.…DB tours remove everything.…Adding a unique index to the documents…only enforces it for entries happening…after the index is created.…So if you know that you want to use a unique index,…you can either set the underscore ID…when creating the document,…or declare one of the fields to be a unique index…before adding documents to the collection.…
- Installing MongoDB for Windows and OS X
- Why Mongo?
- Document-oriented data
- Exploring the Mongo shell
- Importing data into the database
- Building an application in Node.js
- Tuning Mongo queries
- Replication and sharding
Skill Level Intermediate
1. Understand MongoDB
2. Explore the System
3. Build an Application in Node
Node MongoDB setup4m 59s
4. Advanced Topics
- 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.