What means: unknown top level operator: $in on Mongo Java Driver?

4,659 views
Skip to first unread message

Flavio Andrade

unread,
May 20, 2019, 8:45:09 PM5/20/19
to mongodb-user
Hello,

When I use the mongo-java-driver, I have a difficulty with $in operator on update command.

I'm using the MongoDatabase.getCollection(collectionName).updateMany(...) with a command with $in. For this case return:
com.mongodb.MongoWriteException: unknown top level operator: $in

For all others cases with update (without $in) works well.

When this happens is because the mongo-java-driver don't have implementation for $in?

PS: the same mongo command (with $in) works well on mongo shell and runCommand spring data implementation.

Wan Bachtiar

unread,
May 23, 2019, 3:41:16 AM5/23/19
to mongodb-user

I’m using the MongoDatabase.getCollection(collectionName).updateMany(…) with a command with $in. For this case return:

Hi Flavio,

It is likely that you may have skipped specifying field before $in. For example, missing specifying field foo from the below example :

db.collection.update( { "foo": { "$in": ["bar", "baz"] } },
                     { "$set": { "x":true } });

If you have further question, could you provide:

  • MongoDB Java driver version
  • The snippet of the updateMany, i.e. that contains the update operation or command

Regards,
Wan.

Reply all
Reply to author
Forward
0 new messages