1. Java Driver
- Download URL: https://github.com/mongodb/mongo-java-driver/downloads
2. Java Example
import java.net.UnknownHostException;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import com.mongodb.ServerAddress;
public class MongoDB {
public static void main(String[] args) throws UnknownHostException {
MongoClient client = new MongoClient(new ServerAddress("localhost",
27017));
DB database = client.getDB("databaseName");
DBCollection collection = database.getCollection("collectionName");
DBObject document = collection.findOne();
System.out.println(document);
client.close();
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.