lib/mongodoc/collection.rb in mongodoc-0.1.2 vs lib/mongodoc/collection.rb in mongodoc-0.2.0
- old
+ new
@@ -2,44 +2,44 @@
module MongoDoc
class Collection
attr_accessor :_collection
delegate :[], :clear, :count, :create_index, :db, :drop, :drop_index, :drop_indexes, :group, :hint, :index_information, :name, :options, :remove, :rename, :size, :to => :_collection
-
+
def initialize(name)
self._collection = self.class.mongo_collection(name)
end
-
+
def find(query = {}, options = {})
cursor = MongoDoc::Cursor.new(_collection.find(query, options))
if block_given?
yield cursor
cursor.close
else
cursor
end
end
-
+
def find_one(spec_or_object_id = nil, options = {})
MongoDoc::BSON.decode(_collection.find_one(spec_or_object_id, options))
end
-
+
def insert(doc_or_docs, options = {})
_collection.insert(doc_or_docs.to_bson, options)
end
alias :<< :insert
-
+
def save(doc, options = {})
_collection.save(doc.to_bson, options)
end
-
+
def update(spec, doc, options = {})
_collection.update(spec, doc.to_bson, options)
- result = MongoDoc.database.db_command({'getlasterror' => 1})
+ result = MongoDoc.database.command({'getlasterror' => 1})
(result and result.has_key?('updatedExisting')) ? result['updatedExisting'] : false
end
-
+
def self.mongo_collection(name)
MongoDoc.database.collection(name)
end
end
-end
\ No newline at end of file
+end