Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7436841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:18:16+00:00 2026-05-29T10:18:16+00:00

I need to communicate with MongoDB shell via Java To explain in short, I

  • 0

I need to communicate with MongoDB shell via Java
To explain in short, I am using something like Runtime.exec (commons exec specifically) to call MongoDB shell in –eval mode

Using this approach, I am able to successfully invoke MongoDB commands, retrieve the output into a stream (and print to stdout for example)

All is well till this point.

I need to now “parse” this output into something like an array of JSONObject

(I can make use of any JSON library like Jackson, etc. that may be appropriate for this)
so that I can “massage” the output based on some requirements. (Change the format, remove some key value pairs, etc.)

When I look at the output generated by printjson in case of arrays at least, it does not seem to be a valid json array but rather valid json objects separated by new line without the comma in between or enclosing [] that would make it a valid array.

In this case, any suggestions on how to parse this output into some kind of holder objects that I can use to read/modify key value pairs?

I don’t have the json commands at compile time but do know that these commands will always end in a printjson

EDIT –

So to simplify, for example, I am looking for a way to parse the following output into Java Objects –
(The individual key/value pairs are not known at compile time)


{
    "_id" : ObjectId("4db0e0289523f82ff6cd90d4"),
    "calendar_date" : "2009-11-10",
    "product_id" : 8,
    "channel" : "website",
    "country" : "USA",
    "total_unit_count" : 740,
    "total_amount" : 11367.29
}
{
    "_id" : ObjectId("4db0e0289523f82ff6cd90d5"),
    "calendar_date" : "2009-11-10",
    "product_id" : 8,
    "channel" : "website",
    "country" : "Australia",
    "total_unit_count" : 740,
    "total_amount" : 13893.09
}
{
    "_id" : ObjectId("4db0e0289523f82ff6cd90d6"),
    "calendar_date" : "2009-11-10",
    "product_id" : 8,
    "channel" : "retail",
    "country" : "USA",
    "total_unit_count" : 13,
    "total_amount" : 8296.89
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:18:17+00:00Added an answer on May 29, 2026 at 10:18 am

    What I was looking for does not seem possible at the moment.

    What I ended up doing was to shell out the mongo calls, obtain the result stream in java, JSONize the result (get rid of object_id since i dont need it, convert dates appropriately, etc.) and then generate a json object from this modified result string.
    Ugly hack but the only one that seemed possible and it works.

    If you ever find yourself in a similar boat and have specific questions, post in the comment below and I will help if I can.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to communicate with C# application using Window messaging from Java application. From
I need to communicate with another machine using the x.25 protocol and Java. Are
I need to communicate with a hardware device using TCP and with Windows I
Hey, I'm using php 5 and need to communicate with another server that runs
I have handhelds that need to communicate via basicHTTPBinding. I have a contract and
I am writing a Client/Server application need to communicate with each other via RPC.
My .Net application need to communicate with Linux based system which is using following
The system I'm working on is using something like a dynamic router + dep.injection
I need to communicate with a legacy application from my C# app via the
We have 2 separate products that need to communicate with each other via web

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.