Sha256: f43684ec03bc8cd98db716453dfd2aa698b238edbd08cd446bacdafaa68abbd8
Contents?: true
Size: 949 Bytes
Versions: 2
Compression:
Stored size: 949 Bytes
Contents
require 'rubygems' require 'pathname' root_path = Pathname(__FILE__).dirname.join('..').expand_path lib_path = root_path.join('lib') $:.unshift(lib_path) require 'adapter/mongo_atomic' key = BSON::ObjectId.new full_doc = {'a' => 'c', 'b' => 'd'} partial_doc = {'a' => 'z'} client = Mongo::MongoClient.new.db('adapter')['testing'] adapter = Adapter[:mongo].new(client) atomic_adapter = Adapter[:mongo_atomic].new(client) adapter.clear atomic_adapter.clear adapter.write(key, full_doc) adapter.write(key, partial_doc) doc = adapter.read(key) doc.delete('_id') # full doc must always be written with :mongo adapter puts 'Should be {"a"=>"z"}: ' + doc.inspect atomic_adapter.write(key, full_doc) atomic_adapter.write(key, partial_doc) doc = atomic_adapter.read(key) doc.delete('_id') # partial updates can be written with atomic adapter as $set is used puts 'Should be {"a"=>"z", "b"=>"d"}: ' + doc.inspect
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
adapter-mongo-0.8.1 | examples/mongo_atomic.rb |
adapter-mongo-0.8.0 | examples/mongo_atomic.rb |