Mongoose: Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. It provides a straight-forward, schema-based solution to model your application data. Here's an example of how to define a schema and create a model using Mongoose:
php
const mongoose = require('mongoose');
const userSchema = new mongoose.Schema({
name: {
type: String,
required: true
},
age: {
type: Number,
required: true
},
email: {
type: String,
required: true,
unique: true
}
});
const User = mongoose.model('User', userSchema);
module.exports = User;
In this example, we define a user schema that includes a name, age, and email field. We then create a User model using the schema and export it for use in other modules.
No comments:
Post a Comment