Mongoose & MongoDB
How to use the Snippet
Write the snippet in your new file cmmdb
:
schema.js
import mongoose from 'mongoose';
const SchemaNameSchema = new mongoose.Schema({
field1: {
type: String,
required: true,
},
field2: {
type: Number,
required: true,
},
});
const SchemaName = mongoose.model('SchemaName', SchemaNameSchema);
export default SchemaName;
In the snippet above, we created a simple mongoose schema that defines the structure of a document in a MongoDB collection. The schema has two fields: field1
of type String
and field2
of type Number
.
How to use the Command
- Open the command palette
(Ctrl+Shift+P
orCmd+Shift+P on Mac)
. - Type
MERN: Mongoose Function
and pressEnter
. - Enter the schema name.
- Press
Enter
and the snippet will be created.
Show GIF
"Hard work is worthless for those that don’t believe in themselves." - Naruto Uzumaki