Reputation: 215
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?
Upvotes: 7
Views: 28461
Reputation: 1
I had similar issue while using pymongo. Initially I used driver version 3.6, but changed to 3.11 and it solved the issue.
Upvotes: 0
Reputation: 3512
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:
npm install [email protected]
Upvotes: 1
Reputation: 489
Update mongo-java-driver version and try again
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.2</version>
</dependency>
Upvotes: 0
Reputation: 121000
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+.
Upvotes: 5