MongoDB-3
MongoDB-3
SUNITA D RATHOD
Using Mongoose for Structured Schema
and Validation
• Mongoose is an Object Document Model (ODM) that
pipes additional functionality onto the native driver.
• Schema object
• Model object
• Document object
New objects introduced by mongoose
• Schema object: defines the needed structure for the
documents in a given collection.
• Array
• Boolean
• Buffer
• Date
• Mixed (A generic / flexible data type)
• Number
• ObjectId
• String
Creating a Mongoose schema
• To create schema , we need a new instance of the
schema object.
Alert message
Full fledged example:
Expalination:
• We validated Schema types using built-in validators, we
can also pass the alert messages if the validation is failed.
• Request Methods
A good API always returns a response and shouldn’t leave you hanging.
Response and Status code
• Standardizing the API is just as important as the API
request format.
• 200: Success
• 201: Created
• 401: Unauthorized
• 403: Forbidden
• The HTTP methods are the verbs and the resources are
the nouns. The names you use must be as descriptive as
you can make them.
Evaluating API Patterns
• GET vs. POST
• When the API is being designed, we want to make use of
the HTTP methods for any call.
• Performance–ready API
• Evaluate specific servers
• Cost and Time Effectiveness
Thank you