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?
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 has OP_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 issues OP_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+.