Struct MongoCollection
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.
Methods
Method name | Description |
---|---|
this | |
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. |
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);
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.