MongoDB Python and C++ clients - error with multiple instances

回眸只為那壹抹淺笑 提交于 2019-12-11 11:24:43

问题


I'm still new to the MongoDB. My test C++ application is composed from a number of object files, and two of them have their own MongoDB instances. I've found that was a mistake, cause I've got an exception:

terminate called after throwing an instance of 'mongocxx::v_noabi::logic_error'
  what():  cannot create a mongocxx::instance object if one has already been created
Aborted (core dumped)

So, I'll try to define a single MongoDB instance in this application.

And now I worry about my another application - it's top-level program in Python, which loads a number of dynamic libraries, written in C++ and having their own MongoDB instances. Where should I define the MongoDB instance - in the top-level code, in each library, in one of the libraries?


回答1:


You should create one shared library which manages a singleton instance of mongocxx::instance and have all of the other libraries which need to use the driver access that singleton via some common API. Please see the instance management example.



来源:https://stackoverflow.com/questions/50914898/mongodb-python-and-c-clients-error-with-multiple-instances

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!