In order to create a database instance in MongoDB 3.2 you have to write something like that:
new MongoClient().getDatabase("dbName");
According to the official MongoDB Java API 3.2 this should return you a database instance.
My questions:
Do I understand correctly, that if the DB with the specified name does not exist, thus MongoDB will create it for me?
And if the assumption from the question #1 is correct, what will happen if I'll try to request the same DB twice? Will it return just the already existed instance or will drop the existed one and will create a new one?
P.S. Can you, please, advise me a good and updated MongoDB for Java manual/tutorial, I googled for a couple of them, but they are not so updated.
In 3.1.1 driver:
Calling getDatabase doesn't in fact create new database because operation is lazy - it returns database representation. Calling any modifiable operation (e.g. createCollection):
But remember that you have to call any operation which actually performs something - like create. If you just call getDatabase it won't create it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With