Java & MongoDB Tutorial
Java & MongoDB Useful Resources
Selected Reading
- Java & MongoDB - Sorting Records
- Java & MongoDB - Limiting Records
- Java & MongoDB - Referenced Documents
- Java & MongoDB - Embedded Documents
- Java & MongoDB - Delete Document
- Java & MongoDB - Update Document
- Java & MongoDB - Select Document
- Java & MongoDB - Insert Document
- Java & MongoDB - Display Collections
- Java & MongoDB - Drop Collection
- Java & MongoDB - Create Collection
- Java & MongoDB - Drop Database
- Java & MongoDB - Show Databases
- Java & MongoDB - Connect Database
- Java & MongoDB - Environment Setup
- Java & MongoDB - Overview
- Java & MongoDB - Home
Java & MongoDB Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Java & MongoDB - Overview
Java & MongoDB - Overview
MongoDB developer team has provided MongoDB Driver for Java and have various resources available for it.
First step in connecting to MongoDB using Java is to have mongodb driver in the java classpath and then use mongodb API to connect to the database.
Connecting to MongoDB database
Suppose, MongoDB is installed locally and using default port then following syntax connects to MongoDB database.
MongoCpent mongoCpent = MongoCpents.create("mongodb://localhost:27017");
As MongoCpent assumes various default, it can be used using the following way as well.
MongoCpent mongoCpent = MongoCpents.create();
Creating/Connecting to Database
Once mongoCpent is instantiated, its getDatabase() method can be used to get connection to a database.
MongoDatabase database = mongoCpent.getDatabase("myDb");
In case database is not present then above command will create the same.
In subsequent chapters, we ll see the various operations on MongoDB using Java.
Advertisements