Skip to main content

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

  1. Open the command palette (Ctrl+Shift+P or Cmd+Shift+P on Mac).
  2. Type MERN: Mongoose Function and press Enter.
  3. Enter the schema name.
  4. Press Enter and the snippet will be created.
Show GIF

MongoDB Function


"Hard work is worthless for those that don’t believe in themselves." - Naruto Uzumaki