Skip to content
Browse files

Added native read_multiple.

  • Loading branch information...
1 parent 21dd0c8 commit d8bdc2ede9b89ac2f21136034461501fc9586928 @jnunemaker committed Nov 7, 2012
Showing with 16 additions and 0 deletions.
  1. +16 −0 lib/adapter/mongo.rb
View
16 lib/adapter/mongo.rb
@@ -9,6 +9,22 @@ def read(key)
end
end
+ def read_multiple(*keys)
+ ids = keys.map { |key| key_for(key) }
+ docs = client.find('_id' => {'$in' => ids}).to_a
+
+ docs_by_id = BSON::OrderedHash[docs.map { |doc|
+ [doc.delete('_id'), doc]
+ }]
+
+ result = {}
+ keys.each do |key|
+ key = key_for(key)
+ result[key] = docs_by_id[key]
+ end
+ result
+ end
+
def write(key, value)
client.save({'_id' => key_for(key)}.merge(encode(value)), {:safe => options[:safe]})
end

0 comments on commit d8bdc2e

Please sign in to comment.
Something went wrong with that request. Please try again.