Mongodb query using java client

29 Views Asked by At

I need to stransform this example of raw mongo query to java code using the wrappers from java mongodb lib.

{
  "$switch": {
    "branches": [
      {
        "case": { "$eq": ["<field>", <value>] },
        "then": "<result>"
      },
      // Add more branches here if needed
    ],
    "default": ""
  }
}

I'm very new to mongodb and I really will appreaciate your help. I use mongodb client version 7.10.1 (latest for 10.07.2023).

I found I could use the switchOn() function, but not sure how to continue from here:

MqlValue field = current().getField(<field name>);
field.switchOn(f -> f.eq(...));
0

There are 0 best solutions below