marcelnicolay / mongotor

An asynchronous driver and toolkit for accessing MongoDB in Tornado
Other
57 stars 16 forks source link

Add support to replica sets #2

Closed marcelnicolay closed 12 years ago

marcelnicolay commented 12 years ago

from mongotor.database import Database from mongotor.node import ReadPreference from bson import ObjectId

db = Database.connect(["localhost:27027", "localhost:27028"], dbname='test', read_preference=ReadPreference.SECONDARY_PREFERRED)

doc = {'_id': ObjectId()} yield gen.Task(db.test.insert, doc)

wait replication

time.sleep(2)

doc_found, error = yield gen.Task(db.test.find_one, doc)

assert doc_found == doc