Class | Mongoid::Collection |
In: |
lib/mongoid/collection.rb
|
Parent: | Object |
This class is the Mongoid wrapper to the Mongo Ruby driver‘s collection object.
counter | [R] | |
klass | [R] | |
name | [R] |
Initialize a new Mongoid::Collection, setting up the master, slave, and name attributes. Masters will be used for writes, slaves for reads.
@example Create the new collection.
Collection.new(masters, slaves, "test")
@param [ Class ] klass The class the collection is for. @param [ String ] name The name of the collection. @param [ Hash ] options The collection options.
@option options [ true, false ] :capped If the collection is capped. @option options [ Integer ] :size The capped collection size. @option options [ Integer ] :max The maximum number of docs in the
capped collection.
Find the first document from the database given a selector and options.
@example Find one document.
collection.find_one({ :test => "value" })
@param [ Hash ] selector The query selector. @param [ Hash ] options The options to pass to the db.
@return [ Document, nil ] A matching document or nil if none found.
Perform a map/reduce on the documents.
@example Perform the map/reduce.
collection.map_reduce(map, reduce)
@param [ String ] map The map javascript function. @param [ String ] reduce The reduce javascript function. @param [ Hash ] options The options to pass to the db.
@return [ Cursor ] The results.
Updates one or more documents in the collection.
@example Update documents.
collection.update( { "_id" => BSON::OjectId.new }, { "$push" => { "addresses" => { "_id" => "street" } } }, :safe => true )
@param [ Hash ] selector The document selector. @param [ Hash ] document The modifier. @param [ Hash ] options The options.
@since 2.0.0