0

Is there any way to execute a mongo query without the java driver, and get the raw string response in java?

What protocol is used by the mongo server <---> mongo client?

Thanks!

2 Answers 2

2

If it's only about querying (not insert, update, or remove operations), you can use simple REST API included in mongod process. It is generally used for monitoring, alert scripts, and administrative tasks

Examples:

  • To get the contents of a collection:

    http://127.0.0.1:28017/databaseName/collectionName/

  • To add a limit:

    http://127.0.0.1:28017/databaseName/collectionName/?limit=-10

  • To skip:

    http://127.0.0.1:28017/databaseName/collectionName/?skip=5

  • To query for {a : 1}:

    http://127.0.0.1:28017/databaseName/collectionName/?filter_a=1

As per mongo's documentation:

This API is disabled by default, as it could provide unauthenticated access to data. Use --rest on the command line to enable, but be aware of security implications

Check details to enable this.

Sign up to request clarification or add additional context in comments.

4 Comments

This an API provided by MongoDB but it is AFAIK not the one used by MongoDB Java driver (at least in the current version)
@Robert I did not say it is used by MongoDB Java driver.
@Robert OP wants to execute a mongo query without the java driver. So, REST could be a way.
this look promising, i only ned to test the Performance drawbacks over the direct socket access.
2

The Mongo Java Driver uses the "MongoDB Wire protocol". It is a socket oriented BSON communication protocol.

You can see/examine it for example in Wireshark when you connect to a MongoDB database that does not use SSL/TLS (filter for TCP port 27017).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.