In my Node.js project (using VS Code IDE), Mongoose schema intellisense is not shown. I'm doing a Udemy Node.js course. In there, the course instructor's VS Code showed Mongoose schema intellisense. I mean when they typed "type" property, VS Code suggests the "type" property of Mongoose schema. Also for other properties like "required", "default", "min", "max", etc.
But, in my VS Code it doesn't show the mongoose schema intellisense.
I don't use TypeScript, it is just a Vanilla JS (Node.js) project.
I searched the solution for nearly all day long. But couldn't fix my problem.
Some say things like:
npm i mongoose -g(doesn't work for me)npm i @types/mongoose(this NPM package is deprecated 2 years ago)- some say, Mongoose schema intellisense is VS Code default setting and don't need to do any changes. (I completely uninstall [I mean clean uninstall] both VS Code and Node.js, and then reinstall again. But Mongoose schema intellisense is still not shown in my VS Code.)
My Node.js version is v20.2.0.
My VS Code version is 1.78.2 "user" installer
My mongoose npm package version is [email protected]
I'm running on Windows 10
The Udemy instructor used
- [email protected]
- VS Code version "1.49.something"
- Node.JS version "14.11.0"
- and he is running on Mac OS
- no extensions. He said his VS Code IDE is default setting.
The Udemy Node.js course I'm taking is Maximilian Schwarzmüller's "NodeJS - The Complete Guide (MVC, REST APIs, GraphQL, Deno)" [https://www.udemy.com/course/nodejs-the-complete-guide/]
The screen shot of Udemy instructor's video is shown below. The link of that video is [https://www.udemy.com/course/nodejs-the-complete-guide/learn/lecture/11954140#content]. And timespan of the video screen shot is 03:46.
Here is screen shot for my problem (on my VS Code):
Here is my code:
/**
* models/Product.js (Product Model file)
*/
import mongoose from "mongoose";
const Schema = mongoose.Schema;
const productSchema = new Schema({
title: {
type: String,
required: true,
}
});
const Product = mongoose.model('Product', productSchema);
export default Product;
As one of the stackoverflow helper @starball asked, I provided the source of the instructor and my "npm list" below.
Here is Udemy Instructor's Source code [https://github.com/HponeThitHtoo/saving-mongoose] (@starball sorry for my typo in my previous. The Udemy instructor didn't upload his source code on GitHub. He just give a link of zip file in his Udemy Course". So, I uploaded his source code to my GitHub account.)
Here is my npm list @types/mongoose



Your instructor used
[email protected], which was at a point before Mongoose started publishing its own TypeScript type definitions in its own package, so you shouldnpm i -D '@types/mongoose@~5.2.0'. The~means anything matching5.2(any patch version under5.2). The reason why you should do that is because Definitely Typed packages are written to match the major and minor version of the JS package they provide typings for (source).You shouldn't be surprised that what you're trying doesn't work when you're using major version 7 of Mongoose and your instructor is using major version 5. In semver, major versions mean breaking changes.
If you're on a newer major version of mongoose than major version 5, check if you even need the DefinitelyTyped package. For example, on npmjs.com, I can see that major version 8 already packages its own types instead of replying on a DefinitelyTyped package.