Ref: http://mongodb.github.io/mongo-java-driver/
BSON library - build encoder/decoders
MongoDB Driver - legacy API, new generic MongoCollection interface, cross-driver CRUD specification
MongoDB Async Driver - fast non-blocking IO
Core driver - core library
Install - Maven recommended, see the page. "mongodb-driver" recommended for new projects.
Connection pool :
- MongoClient() - make a connection
- Single instance represents pool of connections
- typically just one instance for many threads
- build a singleton - thread safe
- if DO create multiple instance, call close() to clean up
- when instant created, connected
- MongoClient.getDatabase("dbname") - create if not exist
- MongoDatabase.getCollection("name") - create if not exist
- Document
- create: new Document("name","value").append......
- insert: collection.insertOne(doc) : _id auto created collection.insertMany(list<Document>)
- count: collection.count()
- query:
- FindIterable collection.find()
- find() - all docs
- find(eq("i",71) - filtered
- update:
- updateOne, updateMany returns UpdateResult
- updateOne(eq("i",10), new Document("$set", new Document("i",110)));
- UpdateResult updateResult = collection.updateMany(lt("i", 100), inc("i", 100));
- delete: