Azephiar
Azephiar

Reputation: 501

WebStorm 11 unrecognized MongoDb (with mongoose) functions

WebStorm gives me a warning of "Unrecognized function or method" on functions like:

I've tried to Enabling the NodeJs core libraries and to install

under Preferences > JavaScript > Libraries

But this has not solved my problem. Does someone knows a solution?

Upvotes: 4

Views: 3890

Answers (4)

iCPSoni
iCPSoni

Reputation: 136

This is possible solution working for me without any issues.

Moving the relative path out of the require() statement as follows.

const PATH = '../models/';
const User = require(PATH + 'user');

Alternatively

Do not import Schema separately.

Just import mongoose like this

const mongoose = require('mongoose');

and use mongoose.Schema to access Schema

Upvotes: 3

ΓDΛ
ΓDΛ

Reputation: 11070

Note that the schema is inserted correctly. Don't forget to check your Schema.

Sample

 module.exports = mongoose.model('SampleCollection', SampleSchema);

Upvotes: 0

Serdar D.
Serdar D.

Reputation: 3391

I don't know the reason but somehow this works:

export
module.exports.User = User; // your model

import
const User = require("../dbSchema/user.js").User;

Upvotes: 2

lena
lena

Reputation: 93768

This issue is tracked as https://youtrack.jetbrains.com/issue/WEB-17099; please see https://youtrack.jetbrains.com/issue/WEB-17099#comment=27-1441265 for possible workaround

Upvotes: 4

Related Questions