Getting started with MongoDB installation and java Development

Source: Internet
Author: User
Tags mongodb documentation

In the previous blog, we successfully installed and started the Mongo database. In this blog, I will introduce the development of the MongoDB database. For details, refer to the official MongoDB documentation. To smoothly develop MongoDB databases, follow these steps:

1. Download the Mongo database driver. The driver query is very different from the JDBC driver.

Click the address https://github.com/mongodb/mongo-java-driver/downloads to enter the MongoDB java driver download page, download the latest driver.

2. Create a java project, such as MongoDB, create a package com. geostar. mongo. test, and create a class MongoDB.

The MongoDB class is very simple. There is only one main function. Let's just test the MongoDB database.

View Code

ackage com.geostar.mongo.test;

import java.net.UnknownHostException;
import java.util.List;

import com.mongodb.Mongo;

public class MongoDB {
//------MongoDB java driver https://github.com/mongodb/mongo-java-driver/downloads
/**
* @param args
*/
public static void main(String[] args)throws UnknownHostException {
// TODO Auto-generated method stub
Mongo mongo=new Mongo("localhost",27017);
List<String> dbs=mongo.getDatabaseNames();
if(dbs!=null){
for(String name:dbs){
System.out.println("Mongo db name:"+name);
};
};

}

}

Right-click> Run As> Java Application, Run the program, and the console can output:

Mongo db name: local

This is just a simple example, but I think it is okay to get started. If you want to explore its powerful functions, you can continue to explore MongoDB and use the MongoDB database driver to operate the database, you can also use Spring Mongo in the Spring framework to do something complicated.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.