Last active
January 29, 2016 07:03
-
-
Save zerin108/96da502b39c885229ded to your computer and use it in GitHub Desktop.
Mongo for JavaDevelopers Driver
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package mongo; | |
| 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; | |
| import org.bson.Document; | |
| public class App { | |
| public static void main(String[] args) { | |
| MongoClientOptions options = MongoClientOptions.builder().connectionsPerHost(500).build(); | |
| MongoClient client = new MongoClient(new ServerAddress("localhost", 27017), options); | |
| //getting database | |
| MongoDatabase db = client.getDatabase("test").withReadPreference(ReadPreference.secondary()); | |
| MongoCollection<BsonDocument> col = db.getCollection("test", BsonDocument.class); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package mongo; | |
| import org.bson.Document; | |
| public class DocumentTest { | |
| public static void main(String[] args) { | |
| Document document = new Document() | |
| .append("str", "MongoDB, hello!"); | |
| String str = document.getString("str"); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Mongo for JavaDevelopers Driver |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment