When I use mongo-ruby-driver and I insert a new document, it returns the generated '_id':
db = MongoClient.new('127.0.0.1', '27017').db('ruby-mongo-examples') id = db['test'].insert({name: 'example'}) # BSON::ObjectId('54f88b01ab8bae12b2000001')
I try to get the "_id" of the document after pasting with Moped:
db = Moped::Session.new(['127.0.0.1:27017']) db.use('ruby-mongo-examples') id = db['coll'].insert({name: 'example'}) # {"connectionId"=>15, "n"=>0, "syncMillis"=>0, "writtenTo"=>nil, "err"=>nil, "ok"=>1.0}
How to get identifier using Moped?
Update:
I am also trying to use safe mode, but it does not work:
db = Moped::Session.new(['127.0.0.1:27017']) db.use('ruby-mongo-examples') db.with(safe: true) do |safe| id = safe['coll'].insert({name: 'example'}) # {"connectionId"=>5, "n"=>0, "syncMillis"=>0, "writtenTo"=>nil, "err"=>nil, "ok"=>1.0} end
source share