1

コレクションの更新をrubyドライバーからmongodbに呼び出して、戻りコード117を取得します。取得したエラーコードを一般的に解釈するにはどうすればよいですか?

4

1 に答える 1

1

セーフモードを使用している場合、updateメソッドはgetLastErrorの出力を含むハッシュを返します。ただし、セーフモードを使用していない場合は、サーバーに送信されたバイト数を返すだけです。

# setup connection & get handle to collection
connection = Mongo::Connection.new
collection = connection['test']['test']

# remove existing documents
collection.remove
=> true

# insert test document
collection.insert(:_id => 1, :a => 1)
=> 1
collection.find_one
=> {"_id"=>1, "a"=>1}

# we sent a message with 64 bytes to a mongod
collection.update({_id: 1},{a: 2.0})
=> 64 # number of bytes sent to server

# with safe mode we updated one document -- output of getLastError command
collection.update({_id: 1},{a: 3.0}, :safe => true)
=> {"updatedExisting"=>true, "n"=>1, "connectionId"=>19, "err"=>nil, "ok"=>1.0}

これは、ドキュメントでより明確にすることができるものです。次のrubyドライバーリリースのために更新します。

于 2012-06-18T16:26:25.620 に答える