Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package it.terrinoni.m101j; import com.mongodb.MongoClient; import com.mongodb.MongoClientOptions; import com.mongodb.ReadPreference; import com.mongodb.ServerAddress; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import org.bson.BsonDocument; /** * * @author Marco Terrinoni */ public class App { public static void main(String[] args) { MongoClientOptions options = MongoClientOptions.builder().connectionsPerHost(100).build(); MongoClient client = new MongoClient(new ServerAddress(), options); MongoDatabase db = client.getDatabase("test").withReadPreference(ReadPreference.secondary()); MongoCollection<BsonDocument> coll = db.getCollection("test", BsonDocument.class); } }