Add Collection#save

This commit is contained in:
Aman Gupta 2009-05-15 18:21:10 -07:00
parent dfd2f1abc8
commit 2fafddd7fa
1 changed files with 9 additions and 0 deletions

View File

@ -73,6 +73,15 @@ module XGen
cursor.next_object # don't need to explicitly close b/c of limit
end
# Save an updated +object+ to the collection, or insert it if it doesn't exist already.
def save(object)
if id = object[:_id] || object['_id']
modify({:_id => id}, object)
else
insert(object)
end
end
# Insert +objects+, which are hashes. "<<" is aliased to this method.
# Returns either the single inserted object or a new array containing
# +objects+. The object(s) may have been modified by the database's PK