I have a Mix project and I am trying to insert some data into my local database.
I have added the Mongo dependency to my project, then added the lines of code for connecting to the database and for storing data into it.
{:ok, pid} =
Mongo.start_link(
url: "mongodb://localhost:27017/tweet_processor")
{:ok, result} =
Mongo.insert_one(pid, "tweets", tweet_to_insert)
But I keep getting
{:error, %Mongo.Error{
code: 352,
host: nil,
message: "command failed: Unsupported OP_QUERY command: insert"}}
What could be the problem?
4
Answers
I wild guess (out of the shape of commands you’ve shared) that you are using
mongodb
package. It explicitly states it supports MongoDB versions 2.6÷4.0. I also wild guess you are using MongoDB 5+ backend, which hasOP_QUERY
explicitly deprecated.The driver you use is OSS, and from its source code, one might see that
Mongo.insert_one/4
delegates to low-level call which issuesOP_QUERY
.One possibility to fix the issue would be to downgrade MongoDB to v4.0, another (most appreciated by a community) would be to provide a PR to the library, supporting MongoDB 5+.
You can just use this driver which has support for MongoDB 5.x
Update mongo-java-driver version and try again
I was getting the same error. "Unsupported OP_QUERY command: insert" For me this ended up being an issue with Mongoose. After upgrading mongoose to ^6.5.2 it works without issue.
With NPM you can update the package like so: