Discussion:
Java Driver DB as Singleton
Luís Lobo
2014-02-10 11:35:01 UTC
Permalink
Hi!

I am using Google Guice to wrap my instances all across my application.
The MongoClient instance in my app is a Singleton and I think it's
probably the best method.

Is this line of thought valid for the DB instance, or should I get a new
instance for each operation?

Regards,
--
Luís Filipe Lobo <lobo-***@public.gmane.org>
--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongodb-user-/***@public.gmane.org
To unsubscribe from this group, send email to
mongodb-user+unsubscribe-/***@public.gmane.org
See also the IRC channel -- freenode.net#mongodb

---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Jeff Yemin
2014-02-10 13:44:59 UTC
Permalink
Hi Luis,

The MongoClient ensures that there is only a single instance per database
name. In other words:

client.getDB("test") == client.getDB("test")

is always true. So there is no need to manage a separate singleton for
each DB instance.


Regards,
Jeff
Post by Luís Lobo
Hi!
I am using Google Guice to wrap my instances all across my application.
The MongoClient instance in my app is a Singleton and I think it's
probably the best method.
Is this line of thought valid for the DB instance, or should I get a new
instance for each operation?
Regards,
--
--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To unsubscribe from this group, send email to
See also the IRC channel -- freenode.net#mongodb
---
You received this message because you are subscribed to the Google Groups
"mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/groups/opt_out.
--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongodb-user-/***@public.gmane.org
To unsubscribe from this group, send email to
mongodb-user+unsubscribe-/***@public.gmane.org
See also the IRC channel -- freenode.net#mongodb

---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Luís Lobo
2014-02-10 13:58:47 UTC
Permalink
Tank you very much Jeff.
Post by Jeff Yemin
Hi Luis,
The MongoClient ensures that there is only a single instance per
client.getDB("test") == client.getDB("test")
is always true. So there is no need to manage a separate singleton
for each DB instance.
Regards,
Jeff
Hi!
I am using Google Guice to wrap my instances all across my
application.
The MongoClient instance in my app is a Singleton and I think it's
probably the best method.
Is this line of thought valid for the DB instance, or should I get a new
instance for each operation?
Regards,
--
--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To unsubscribe from this group, send email to
See also the IRC channel -- freenode.net#mongodb
<http://freenode.net#mongodb>
---
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it,
For more options, visit https://groups.google.com/groups/opt_out.
--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To unsubscribe from this group, send email to
See also the IRC channel -- freenode.net#mongodb
---
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/groups/opt_out.
--
Luís Filipe Lobo <lobo-***@public.gmane.org>
--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongodb-user-/***@public.gmane.org
To unsubscribe from this group, send email to
mongodb-user+unsubscribe-/***@public.gmane.org
See also the IRC channel -- freenode.net#mongodb

---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Loading...