Equivalent of $objectToArray using Mongodb java driver 3

Equivalent of $objectToArray using Mongodb java driver 3

I am moving a Mongodb query from Javascript to Java. The object format is as follows:

I am moving a Mongodb query from Javascript to Java. The object format is as follows:

{
  "record": {
    "unknownName1": {
      "count": 5,
      "domain": "domain1"
    }, {
    ...
    }, {
    "unknownNameN": {
      "count": 3,
      "domain": "domainN"
    }
  }
}

The Javascript query has the following portion:

[
  { 
    $project: {
      record: { 
        $objectToArray: "$record" 
      }
    }
  }, {
    $unwind: { "$record"
  }, {
    $group: {
      device: "$record.k"
    }, 
    count: {
      $sum: "$record.v.count"
    },
    domain: {
      $min: "$record.v.domain"
    }
  }
]

I have translated the above to use the Mongodb Java Driver 3 api and have the following:

List<Bson> query = Arrays.asList(
    project(include("record")),
    unwind("$record"),
    group(computed("device", "$record.k"),
        sum("count", "$record.v.count"),
        min("domain", "$record.v.domain"))
);

The issue I am having is I can't seem to find an equivalent to $objectToArray using the Mongodb Java Driver and the subsequent sum and min operations depend on dot operating the k and v values generated from using $objectToArray.

Is there an equivalent way to map an object with unknown key names into the k and v format used by $objectToArray using the Mongodb Java Driver, preferrably version 3+?

java mongodb

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

MongoDB Database and java applications

Enroll for free demo to acquire the best knowledge on the schema-less database from live industry experts through MongoDB training

How to Build a CRUD API with Java, MongoDB, and Spring Boot

This tutorial shows how to build a CRUD API with Java, MongoDB, and Spring Boot. How to build a CRUD API with Java and MongoDB. In this tutorial, you create a Java data model class and mapped it to a MongoDB domain document using Spring Data annotations. You use a simple embedded MongoDB database as the datastore. You use Spring Boot to quickly and easily expose your data model via a REST API. Finally, you secured the REST API using Okta and Okta’s Spring Boot Starter.

Java Core (2020) | Java for beginners | Brush up your Java Skills | Get Hired

In this video we will learn about all the major concepts that come under Java Core . The course is very carefully designed and is made with keeping simplicit...

Developing Apps with MongoDB and Java

Want to get started with MongoDB and Java? Developing Apps with MongoDB and Java - Learn how to set up your Java project with Maven and execute a MongoDB command in Java.

Which is the Best MongoDB GUI?

Our MongoDB Online Training provide you to learn about MongoDB strategies with realty. Our MongoDB Online Training also includes live sessions, live Projects, and much