How to create a Java mongodb driver query that is identical to this mongodb update query with arrayfilter

Demo Mongo playground.

I found examples to do with spring-mongodb. But unable to find any working way to do this with mongodb driver based code.

Query:


 db.collection.update({
  pollID: 123
},
{
  "$inc": {
    "answerAnalytics.$[element].selectCount": 1
  }
},
{
  "arrayFilters": [
    {
      "$or": [
        {
          "element.option": "1"
        },
        {
          "element.option": "2"
        }
      ]
    }
  ],
  "multi": true
})

I have tried doing something like this

 DBCollectionFindAndModifyOptions dbCollectionFindAndModifyOptions = (new DBCollectionFindAndModifyOptions()).projection((DBObject) null).sort((DBObject) null).remove(false).update(incrObj).returnNew(true).upsert(false).bypassDocumentValidation(true).maxTime(0L, TimeUnit.MILLISECONDS).writeConcern(writeConcern);

  
DBObject dbObject = dbCollection.findAndModify(queryDocument, dbCollectionFindAndModifyOptions);

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.