Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added atomic example.

  • Loading branch information...
commit d1541bd08e23f8608e98c6798dc6eabdb71ef7e4 1 parent 1c5b153
@jnunemaker authored
Showing with 22 additions and 0 deletions.
  1. +22 −0 examples/mongo_atomic.rb
View
22 examples/mongo_atomic.rb
@@ -0,0 +1,22 @@
+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'
+
+client = Mongo::Connection.new.db('adapter')['testing']
+adapter = Adapter[:mongo_atomic].new(client)
+adapter.clear
+
+oid = BSON::ObjectId.new
+
+adapter.write(oid, {'a' => 'c', 'b' => 'd'})
+adapter.write(oid, {'a' => 'z'})
+
+doc = adapter.read(oid)
+
+puts 'Should be "z": ' + doc['a']
+puts 'Should be "d": ' + doc['b']
Please sign in to comment.
Something went wrong with that request. Please try again.