cannot create a mongocxx::instance object if one has already been createdPretty-print C++ STL containersHow to implement the factory method pattern in C++ correctlycall_once with once_flag shared across DLLsIs legal use initializer_list to initialize an object with derived types?Is there a way to use a std::pair<> in a class constructorCreating an object via a lambda that captures variables(__imp_? Name decorationmove copy and/or assign a mongodb cxx cursorQt break down by MongoDB C++ initializationError while loading shared libraries: libbsoncxx.so._noabi: cannot open shared object file: No such file or directory
12V lead acid charger with LM317 not charging
Getting an entry level IT position later in life
What could prevent players from leaving an island?
Does the length of a password for Wi-Fi affect speed?
What is the German idiom or expression for when someone is being hypocritical against their own teachings?
Unexpected route on a flight from USA to Europe
Why don't the open notes matter in guitar chords?
How to continue a line in Latex in math mode?
Traveling from Germany to other countries by train?
Can I enter a rental property without giving notice if I'm afraid a tenant may be hurt?
Purchased new computer from DELL with pre-installed Ubuntu. Won't boot. Should assume its an error from DELL?
Is this cheap "air conditioner" able to cool a room?
Why can I log in to my Facebook account with a misspelled email/password?
Why do proponents of guns oppose gun competency tests?
Is DC heating faster than AC heating?
Is it a bad idea to offer variants of a final exam based on the type of allowed calculators?
Is Odin inconsistent about the powers of Mjolnir?
Will a paper be retracted if a flaw in released software code invalidates its central idea?
Determine Beckett Grading Service (BGS) Final Grade
How would a family travel from Indiana to Texas in 1911?
Our group keeps dying during the Lost Mine of Phandelver campaign. What are we doing wrong?
Decode a variable-length quantity
Does this smartphone photo show Mars just below the Sun?
How to halve redstone signal strength?
cannot create a mongocxx::instance object if one has already been created
Pretty-print C++ STL containersHow to implement the factory method pattern in C++ correctlycall_once with once_flag shared across DLLsIs legal use initializer_list to initialize an object with derived types?Is there a way to use a std::pair<> in a class constructorCreating an object via a lambda that captures variables(__imp_? Name decorationmove copy and/or assign a mongodb cxx cursorQt break down by MongoDB C++ initializationError while loading shared libraries: libbsoncxx.so._noabi: cannot open shared object file: No such file or directory
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I made an class to invoke and test mongo-cxx-driver and I create an mongocxx::instance
in my constructor.
MongoDBHelper::MongoDBHelper()
mongocxx::instance inst;
The problem is when I init the second instance of my class object, it turns out:
cannot create a mongocxx::instance object if one has already been created
it would be a little strange if I put mongocxx::instance
in the global scope or use std::call_once
. How can I fix it?
c++ mongodb
add a comment |
I made an class to invoke and test mongo-cxx-driver and I create an mongocxx::instance
in my constructor.
MongoDBHelper::MongoDBHelper()
mongocxx::instance inst;
The problem is when I init the second instance of my class object, it turns out:
cannot create a mongocxx::instance object if one has already been created
it would be a little strange if I put mongocxx::instance
in the global scope or use std::call_once
. How can I fix it?
c++ mongodb
Why not make it a class static variable if global feels strange? It seems like it wants to be treated as a singleton instance.
– kmdreko
Mar 27 at 6:44
@kmdreko thanks
– Peiwen_hao
Mar 27 at 9:07
add a comment |
I made an class to invoke and test mongo-cxx-driver and I create an mongocxx::instance
in my constructor.
MongoDBHelper::MongoDBHelper()
mongocxx::instance inst;
The problem is when I init the second instance of my class object, it turns out:
cannot create a mongocxx::instance object if one has already been created
it would be a little strange if I put mongocxx::instance
in the global scope or use std::call_once
. How can I fix it?
c++ mongodb
I made an class to invoke and test mongo-cxx-driver and I create an mongocxx::instance
in my constructor.
MongoDBHelper::MongoDBHelper()
mongocxx::instance inst;
The problem is when I init the second instance of my class object, it turns out:
cannot create a mongocxx::instance object if one has already been created
it would be a little strange if I put mongocxx::instance
in the global scope or use std::call_once
. How can I fix it?
c++ mongodb
c++ mongodb
asked Mar 27 at 5:21
Peiwen_haoPeiwen_hao
212 bronze badges
212 bronze badges
Why not make it a class static variable if global feels strange? It seems like it wants to be treated as a singleton instance.
– kmdreko
Mar 27 at 6:44
@kmdreko thanks
– Peiwen_hao
Mar 27 at 9:07
add a comment |
Why not make it a class static variable if global feels strange? It seems like it wants to be treated as a singleton instance.
– kmdreko
Mar 27 at 6:44
@kmdreko thanks
– Peiwen_hao
Mar 27 at 9:07
Why not make it a class static variable if global feels strange? It seems like it wants to be treated as a singleton instance.
– kmdreko
Mar 27 at 6:44
Why not make it a class static variable if global feels strange? It seems like it wants to be treated as a singleton instance.
– kmdreko
Mar 27 at 6:44
@kmdreko thanks
– Peiwen_hao
Mar 27 at 9:07
@kmdreko thanks
– Peiwen_hao
Mar 27 at 9:07
add a comment |
1 Answer
1
active
oldest
votes
from : http://mongocxx.org/api/current/classmongocxx_1_1instance.html
Class representing an instance of the MongoDB driver.
The constructor and destructor initialize and shut down the driver, respectively. Therefore, an instance must be created before using the driver and must remain alive until all other mongocxx objects are destroyed. After the instance destructor runs, the driver may not be used.
Exactly one instance must be created in a given program. Not constructing an instance or constructing more than one instance in a program are errors, even if the multiple instances have non-overlapping lifetimes.
It seems you can't have 2 instances, but maybe you can create/destroy one then recreate/destroy an other.
Where your first instance come from?
1
"even if the multiple instances have non-overlapping lifetimes" means it won't let you recreate it
– kmdreko
Mar 27 at 7:38
Well, so static/singleton/global is forced by design
– Martin Morterol
Mar 27 at 7:55
Unfortunately, yes. Libraries that mongocxx depends on in turn enforce singleton initialization semantics, so there is little we can do. I would have much preferred to design a stateless library, but I was forced to compromise.
– acm
Mar 27 at 19:46
1
At one point, you actually could destroy and re-create the instance, but that feature was removed by a subsequent maintainer because apparently the underlying C driver can't handle that: github.com/mongodb/mongo-cxx-driver/commit/…
– acm
Mar 27 at 19:48
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55370281%2fcannot-create-a-mongocxxinstance-object-if-one-has-already-been-created%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
from : http://mongocxx.org/api/current/classmongocxx_1_1instance.html
Class representing an instance of the MongoDB driver.
The constructor and destructor initialize and shut down the driver, respectively. Therefore, an instance must be created before using the driver and must remain alive until all other mongocxx objects are destroyed. After the instance destructor runs, the driver may not be used.
Exactly one instance must be created in a given program. Not constructing an instance or constructing more than one instance in a program are errors, even if the multiple instances have non-overlapping lifetimes.
It seems you can't have 2 instances, but maybe you can create/destroy one then recreate/destroy an other.
Where your first instance come from?
1
"even if the multiple instances have non-overlapping lifetimes" means it won't let you recreate it
– kmdreko
Mar 27 at 7:38
Well, so static/singleton/global is forced by design
– Martin Morterol
Mar 27 at 7:55
Unfortunately, yes. Libraries that mongocxx depends on in turn enforce singleton initialization semantics, so there is little we can do. I would have much preferred to design a stateless library, but I was forced to compromise.
– acm
Mar 27 at 19:46
1
At one point, you actually could destroy and re-create the instance, but that feature was removed by a subsequent maintainer because apparently the underlying C driver can't handle that: github.com/mongodb/mongo-cxx-driver/commit/…
– acm
Mar 27 at 19:48
add a comment |
from : http://mongocxx.org/api/current/classmongocxx_1_1instance.html
Class representing an instance of the MongoDB driver.
The constructor and destructor initialize and shut down the driver, respectively. Therefore, an instance must be created before using the driver and must remain alive until all other mongocxx objects are destroyed. After the instance destructor runs, the driver may not be used.
Exactly one instance must be created in a given program. Not constructing an instance or constructing more than one instance in a program are errors, even if the multiple instances have non-overlapping lifetimes.
It seems you can't have 2 instances, but maybe you can create/destroy one then recreate/destroy an other.
Where your first instance come from?
1
"even if the multiple instances have non-overlapping lifetimes" means it won't let you recreate it
– kmdreko
Mar 27 at 7:38
Well, so static/singleton/global is forced by design
– Martin Morterol
Mar 27 at 7:55
Unfortunately, yes. Libraries that mongocxx depends on in turn enforce singleton initialization semantics, so there is little we can do. I would have much preferred to design a stateless library, but I was forced to compromise.
– acm
Mar 27 at 19:46
1
At one point, you actually could destroy and re-create the instance, but that feature was removed by a subsequent maintainer because apparently the underlying C driver can't handle that: github.com/mongodb/mongo-cxx-driver/commit/…
– acm
Mar 27 at 19:48
add a comment |
from : http://mongocxx.org/api/current/classmongocxx_1_1instance.html
Class representing an instance of the MongoDB driver.
The constructor and destructor initialize and shut down the driver, respectively. Therefore, an instance must be created before using the driver and must remain alive until all other mongocxx objects are destroyed. After the instance destructor runs, the driver may not be used.
Exactly one instance must be created in a given program. Not constructing an instance or constructing more than one instance in a program are errors, even if the multiple instances have non-overlapping lifetimes.
It seems you can't have 2 instances, but maybe you can create/destroy one then recreate/destroy an other.
Where your first instance come from?
from : http://mongocxx.org/api/current/classmongocxx_1_1instance.html
Class representing an instance of the MongoDB driver.
The constructor and destructor initialize and shut down the driver, respectively. Therefore, an instance must be created before using the driver and must remain alive until all other mongocxx objects are destroyed. After the instance destructor runs, the driver may not be used.
Exactly one instance must be created in a given program. Not constructing an instance or constructing more than one instance in a program are errors, even if the multiple instances have non-overlapping lifetimes.
It seems you can't have 2 instances, but maybe you can create/destroy one then recreate/destroy an other.
Where your first instance come from?
answered Mar 27 at 6:48
Martin MorterolMartin Morterol
1,1311 gold badge2 silver badges8 bronze badges
1,1311 gold badge2 silver badges8 bronze badges
1
"even if the multiple instances have non-overlapping lifetimes" means it won't let you recreate it
– kmdreko
Mar 27 at 7:38
Well, so static/singleton/global is forced by design
– Martin Morterol
Mar 27 at 7:55
Unfortunately, yes. Libraries that mongocxx depends on in turn enforce singleton initialization semantics, so there is little we can do. I would have much preferred to design a stateless library, but I was forced to compromise.
– acm
Mar 27 at 19:46
1
At one point, you actually could destroy and re-create the instance, but that feature was removed by a subsequent maintainer because apparently the underlying C driver can't handle that: github.com/mongodb/mongo-cxx-driver/commit/…
– acm
Mar 27 at 19:48
add a comment |
1
"even if the multiple instances have non-overlapping lifetimes" means it won't let you recreate it
– kmdreko
Mar 27 at 7:38
Well, so static/singleton/global is forced by design
– Martin Morterol
Mar 27 at 7:55
Unfortunately, yes. Libraries that mongocxx depends on in turn enforce singleton initialization semantics, so there is little we can do. I would have much preferred to design a stateless library, but I was forced to compromise.
– acm
Mar 27 at 19:46
1
At one point, you actually could destroy and re-create the instance, but that feature was removed by a subsequent maintainer because apparently the underlying C driver can't handle that: github.com/mongodb/mongo-cxx-driver/commit/…
– acm
Mar 27 at 19:48
1
1
"even if the multiple instances have non-overlapping lifetimes" means it won't let you recreate it
– kmdreko
Mar 27 at 7:38
"even if the multiple instances have non-overlapping lifetimes" means it won't let you recreate it
– kmdreko
Mar 27 at 7:38
Well, so static/singleton/global is forced by design
– Martin Morterol
Mar 27 at 7:55
Well, so static/singleton/global is forced by design
– Martin Morterol
Mar 27 at 7:55
Unfortunately, yes. Libraries that mongocxx depends on in turn enforce singleton initialization semantics, so there is little we can do. I would have much preferred to design a stateless library, but I was forced to compromise.
– acm
Mar 27 at 19:46
Unfortunately, yes. Libraries that mongocxx depends on in turn enforce singleton initialization semantics, so there is little we can do. I would have much preferred to design a stateless library, but I was forced to compromise.
– acm
Mar 27 at 19:46
1
1
At one point, you actually could destroy and re-create the instance, but that feature was removed by a subsequent maintainer because apparently the underlying C driver can't handle that: github.com/mongodb/mongo-cxx-driver/commit/…
– acm
Mar 27 at 19:48
At one point, you actually could destroy and re-create the instance, but that feature was removed by a subsequent maintainer because apparently the underlying C driver can't handle that: github.com/mongodb/mongo-cxx-driver/commit/…
– acm
Mar 27 at 19:48
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55370281%2fcannot-create-a-mongocxxinstance-object-if-one-has-already-been-created%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why not make it a class static variable if global feels strange? It seems like it wants to be treated as a singleton instance.
– kmdreko
Mar 27 at 6:44
@kmdreko thanks
– Peiwen_hao
Mar 27 at 9:07