MongoDB Python和C ++客户端-多个实例出错 [英] MongoDB Python and C++ clients - error with multiple instances

查看:272
本文介绍了MongoDB Python和C ++客户端-多个实例出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还是MongoDB的新手.我的测试C ++应用程序由许多目标文件组成,其中两个拥有自己的MongoDB实例.我发现这是一个错误,因为我有一个例外:

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)

因此,我将尝试在此应用程序中定义一个MongoDB实例.

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

现在我担心我的另一个应用程序-它是Python中的顶级程序,该程序加载许多用C ++编写并具有自己的MongoDB实例的动态库.我应该在哪里定义MongoDB实例-在顶层代码中,在每个库中,在一个库中?

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?

推荐答案

您应该创建一个共享库,该共享库管理mongocxx::instance的单例实例,并使所有其他需要使用驱动程序的库通过一些驱动程序访问该单例.通用API.请参阅 instance管理示例.

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.

这篇关于MongoDB Python和C ++客户端-多个实例出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆