Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebStorm 11 unrecognized MongoDb (with mongoose) functions

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

  • Schema.find() [find() not recognized]
  • Schema.aggregate() [aggregate() not recognized]
  • Schema.findOneAndUpdate() [findOneAndUpdate() not recognized]

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

  • mongodb-DefinitelyType
  • mongoose-DefinitelyType
  • mongoose-auto-increment-DefinitelyType
  • mongoose-deep-populate-DefinitelyType
  • mongoose-DefinitelyType
  • mongoose-mock-DefinitelyType

under Preferences > JavaScript > Libraries

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

like image 381
Azephiar Avatar asked Jan 05 '23 22:01

Azephiar


2 Answers

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

like image 72
lena Avatar answered Jan 22 '23 22:01

lena


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

like image 21
iCPSoni Avatar answered Jan 22 '23 22:01

iCPSoni