Webstorm and mongoDB

Hi, I am using Webstorm IDE, currently, I am facing a weird error with MongoDB, the methods below should normally work but Webstorm refuses to accept the method signature. anyone knows why?

3 comments
Comment actions Permalink

can't reproduce

please could you share a complete code snippet (as text)?

0
Comment actions Permalink
import { MongoClient } from "mongodb";
const uri =
"";

const client = new MongoClient(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
export default function handler(req, res) {
if (req.method === "GET") {
try {
client.connect(async function (err) {
const db = client.db();
const collection = db.collection("test");
const result = await collection.find({}, { _id: 1 }).toArray();
console.log("result", result);
res.status(200).json(result);

// perform actions on the collection object
await client.close();
});
} catch (error) {
client
.close()
.then(() => res.status(500).json({ message: "Fetch message failed" }));
}
}
}

 

0
Comment actions Permalink

The problem is that the IDE analyzes the code statically, using the library typings (node_modules\mongodb\mongodb.d.ts) for types resolving. But none of find() method overloads in this file match this call (as _id property is not defined in FindOptions interface), so it uses the first overload (without params0 and reports an error about unexpected number of arguments

0

Please sign in to leave a comment.