Struct MongoCollection

Represents a single collection inside a MongoDB.

All methods take arbitrary types for Bson arguments. serializeToBson() is implicitly called on them before they are send to the database. The following example shows some possible ways to specify objects.

Constructors

Name Description
this
this

Properties

Name Type Description
database [get] MongoDatabase
name [get] string

Methods

Name Description
aggregate Calculates aggregate values for the data in a collection.
count Counts the results of the specified query expression.
dropIndex
ensureIndex
find Queries the collection for existing documents.
findAndModify Combines a modify and find operation to a single atomic operation.
findOne Queries the collection for existing documents.
insert Inserts new documents into the collection.
remove Removes documents from the collection.
update Performs an update operation on documents matching 'selector', updating them with 'update'.

Examples

MongoClient client = connectMongoDB("127.0.0.1");
MongoCollection users = client.getCollection("myapp.users");

// canonical version using a Bson object
users.insert(Bson(["name": Bson("admin"), "password": Bson("secret")]));

// short version using a string[string] AA that is automatically
// serialized to Bson
users.insert(["name": "admin", "password": "secret"]);

// BSON specific types are also serialized automatically
BsonObjectId uid = ...;
Bson usr = users.find(["_id": uid]);

// JSON is another possibility
Json jusr = parseJson("{\"name\": \"admin\", \"password\": \"secret\"}");
users.insert(jusr);

Authors

Sönke Ludwig

Copyright

© 2012-2014 RejectedSoftware e.K.

License

Subject to the terms of the MIT license, as written in the included LICENSE.txt file.