MongoDB.live, free & fully virtual. June 9th - 10th. Register Now

C++ MongoDB client

Hey,
I’m developing a real time embedded application which requires onboard-embedded DB. I decided to use mongodb and now i’m trying to integrate “dbclient” to my sw for inserting and querying data to/from the local server.
Im using “dbclient.h” and creating bson objects using this example (https://mongodb-documentation.readthedocs.io/en/latest/ecosystem/tutorial/getting-started-with-cpp-driver.html). I have encountered a problem with inserting /indexing geo data (using geojson format) and looked for code examples… but bearly found any c++ examples.
I noticed that there are several ways to implement mongo DB client… also with mongocxx.
Which way is the “Good” way? can you refer me with end-to-end c++ example of indexing and querying geo data?
Thanks

Hi @Arieh_Salomon, welcome!

I would recommend to review the documentation on http://mongocxx.org/mongocxx-v3/tutorial/ and http://mongocxx.org/mongocxx-v3/working-with-bson/

Please see Tutorial: Query Collection , Tutorial: Insert One, and MongoDB GeoSpatial Queries to get started.

If you’re still encountering a problem, please provide:

  • MongoDB C++ driver version
  • An example document
  • An example code snippet that perform the query
  • The problem that you’re encountering
  • The desired output from the query

Regards,
Wan.

Thanks!
So if I understand correctly, <dbclient.h> is the old driver and is the newer (recommended) version?

I installed the latest version (3.5 i think…) and already did the recommended examples.

I’m trying to insert lots of geographic points with descriptor, something like this:

{
“name”: “name_1”,
“location”: {
“coordinates”: [39.301, 21.211],
“type” : “point”
}
“descriptor” : “12345789abcdef”
}

I need to be able to perform a query to get all the points within a certain polygon.

Can you show me a relevant example of how to insert, index and query (c++ code)?

Thanks!