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?
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
can't reproduce
please could you share a complete code snippet (as text)?
import { MongoClient } from "mongodb";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" }));
}
}
}
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