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.
Examples
MongoDB db = connectMongoDB("127.0.0.1"); MongoCollection users = m_db["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);
Constructors
Name | Description |
---|---|
this |
Properties
Name | Type | Description |
---|---|---|
databaseName | string | Returns the name of the database to which this collection belongs. |
name | string | Returns the name of this collection (excluding the database name ). |
Methods
Name | Description |
---|---|
update | Performs an update operation on documents matching 'selector ', updating them with 'update '. |
insert | Inserts new documents into the collection. |
find | Queries the collection for existing documents. |
findOne | Queries the collection for existing documents. |
remove | Removes documents from the collection. |
findAndModify | Combines a modify and find operation to a single atomic operation. |
count | Counts the results of the specified query expression. |
ensureIndex | |
dropIndex |
Authors
Sönke Ludwig
Copyright
© 2012 RejectedSoftware e.K.
License
Subject to the terms of the MIT license, as written in the included LICENSE.txt file.