0

I am beginning to explore MongoDB and wish to write a small program/script using TCP socket to create a document in my local MongoDB community edition server. I would like to access MongoDB (which is now locally installed and running on my laptop) via a TCP socket.

I have installed MongoDB 4.2.3 community edition (with Compass.) As far as I can tell, it is running.

I can run mongo.exe shell:

C:\Program Files\MongoDB\Server\4.2\bin>mongo.exe

and the "show dbs" command yields what I would expect given that no documents or other data have been uploaded:

show dbs admin 0.000GB config 0.000GB local 0.000GB

Now, I would like to access mongodb via a TCP socket opened by my own (very small/simple) program so I can experiment with generating commands and observing responses (such as "show dbs").

When I telnet to localhost:27017 (using Windows 10 telnet client) telnet appears to connect to a socket (screen switches from "Connecting to localhost..." to a blank screen after a few seconds.)

As I am a beginner with MongoDB, I would appreciate a pointer as to how I can achieve my goal of using a small program I write to interact with MongoDB server.

Thank you, and I am happy to supply additional details as needed (and of course, would be grateful to a pointer to an example or other learning material that would help me proceed.)

Dave

wb0gaz
  • 43
  • 1
  • 7

1 Answers1

0

MongoDB uses a custom wire protocol described here

If you are able to send binary values via telnet, you could probably make that work (I've no intention of trying)

You would probably find is simpler to use one of the pre-made drivers

Joe
  • 25,000
  • 3
  • 22
  • 44
  • Thank you Joe! That's actually a good outcome, and makes much more sense than sending/receiving text commands. I've started browsing the material you pointed me to, and once I can get a simple command/response to work, I should be able make good progress. – wb0gaz Mar 14 '20 at 18:45
  • Thank you Joe - the references you point me to look promising. Much appreciate you taking the tie to reply. - Dave – wb0gaz Mar 14 '20 at 18:46