I have a JS application where I have a mongodb driver. After connecting to it I try to run
const result = await db.command(eval(commandString));
in order to run diverse types of commands into my database from a string, for example:
db.collection(“users”).updateOne(
{
name: “Rodrigo”
},
{
$set: {
age: 24
}
}
)
When I trigger the query is executed correctly in the database, and the document is updated, but the Mongo Server receives
MongoServerError: command not found
I want to get rid of this error message and just have the query executed successfully.
I've tried running different commands but all of them have the same behavior.
db.command()method is unable to find command you are trying to execute because it isn't a valid MongoDB command. FYI,eval()method in MongoDB is deprecated.you should use the appropriate methods provided by the MongoDB driver for Node.js :