Last active
February 18, 2016 15:43
-
-
Save drorasaf/1f5183de67dedaafe948 to your computer and use it in GitHub Desktop.
basic tutorial for mongodb for java client
This file contains 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
import com.mongodb.MongoClient; | |
import com.mongodb.client.MongoCollection; | |
import com.mongodb.client.MongoDatabase; | |
import org.bson.Document; | |
import com.mongodb.client.FindIterable; | |
Client mongoClient = new MongoClient(new MongoClientURI("mongodb://localhost:27017")); | |
MongoDatabase database = mongoClient.getDB("Tutorial"); | |
MongoCollection collection = database.getCollection("customers"); | |
Document person = new Document("_id", 1213456789) | |
.append("name", "John Dough") | |
.append("address", | |
new Document("street", "Over the rainbow St") | |
.append("city", "Somewhere") | |
.append("state", "CA") | |
.append("zip", 88888)); | |
collection.insert(person); | |
Document query = new Document("_id", 1213456789); | |
FindIterable<Document> iterable = collection.find(query); | |
Document person = iterable.first(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment