This Visual Studio Code extension is built for Node-js projects. It provides:
- Code Snippets for MongoDB Connection and queries.
- Command Palette Feature to Set up Boilerplate Code.
- Completion Suggestions for Mongoose Models.
- Mongo Connect directly from the editor.
Table of Contents:
Note: Ctrl+Shift+P or Command+Shift+P opens Command Palette in VSCode.
Mongo Snippets: Refer to Mongoose Documentation
Mongo Snippets: Refer to Extension Documentation
Mongo Snippets: Set up Mongo Boilerplate Code
- Creates folders named
models - if they do not exist - in the
source directory, and adds files containing boilerplate code.
Mongo Snippets: Show Existing Models
- Shows a list of names of models present in the
models folder in the
- Highlights the model definition in the file where it had been created.
Mongo Snippets: View MongoDB Collection as JSON
Note: This is a beta feature and will be receive updates soon.
- Connect to a MongoDB instance using a connection string and view a DB as a JSON.
Note: See User's Notes for details.
- Model name suggestions:
- First it identifies the names of the models in a folder named models (if any) in the
- It stores the model and field names and provides completion suggestions when you type.
- Suggests field names for models. E.G. if the model
User has a field
name, on typing
name is suggested.
- Field names are also suggested inside
The following are some of the snippets that can be generated with this extension.
Note: Type the following snippets and press 'Tab' OR 'Ctrl/Command + Space; Enter' for auto-completion.
||MongoDB connect on port 27017
||MongoDB Generate User Model
||Generate typical user model
|Methods and Statics:
There are no dependencies for this extension to work, but it provides mongoose-js snippets, hence mongoose should be installed.
- mongoose library from npm.
This can be installed by executing the following command in the folder where 'package.json' is present.
npm install mongoose
Make sure mongoose is added as a dependency in package.json
Please report issues on vscode-MongoSnippets-NodeJS.
- The source directory, as mentioned multiple times, is by default the root directory of your workspace. It can be modified by adding the following to
.vscode/settings.json in your workspace root directory.
- The above line changes the
source directory from the root directory of the workspace to a folder named
src in the root directory.
The boilerplate is set up in the
source directory of the workspace. In order to set up the boilerplate code in a certain directory, that directory must be open in a new workspace. (Open the folder you want the boilerplate code in with VSCode).
Model name suggestions are only given for those models defined in files present in a directory called
models in the
source directory of the workspace. Folders with other names are not checked, hence models defined in them will not show up as suggestions.
In files where models are described, to be able to detect the models, mongoose must be imported as
mongoose only. For example,
- const mongoose = require('mongoose');
- import mongoose from 'mongoose';
The model must be created in the models folder as follows:
- const modelName = mongoose.model('modelName', modelSchema)
Mongo Snippets: See Existing Models command shows models only in the
source directory of the workspace.
For field name suggestions, each model should be exported in a seperate file, and the file should not have errors.
These are the release notes for mongo-snippets-for-node-js.
- Bump lodash to newer version.
- GitHub release action issues fixed.
- GitHub release action added.
- Use VSCE to publish.
- Publish using GitHub actions.
- CompletionItemProvider code optimization.
- General working of the extension.
.vscode/settings.json under key
- Set up boilerplate, make folders awaited.
- Lots of code refactor, remove lint warnings and errors.
- Code quality improvements.
- Code should run faster now.
- Should take lesser processing power.
- Typescript support for existing features.
You can contribute to mongo-snippets-for-node-js on the GitHub page vscode-MongoSnippets-NodeJS. Checkout CONTRIBUTING.md for further details.
Click the following hyperlink to view the license.
For more information
You can checkout the source code and contribute on: