为什么Mongo有时写,有时不写?代码可能会更好地了解我在说什么:
注意:
dbMongo = Mongo::Connection.new.db("test") #Mongo Database.
coll = dbMongo.collection("test-collection")
glob = Array.new
#///////Generates hashes////
(1...100).to_a.pmap(10) do |x|
b_test = stack_hash(x) #generates an array of hashes
glob << b_test
end
#///////Tests/////
glob = glob.flatten.uniq.compact
p glob.length #=> 3027
p coll.drop #=> true
coll.insert(glob)
p coll.count.to_s + " <batch insert" #=> "2550 <batch insert"
p coll.drop #=> true
glob.each do |x|
coll.insert(x)
end
p coll.count.to_s + " <single thread insert" #=> "3000 <single thread insert"
p coll.drop #=> true
glob.each do |x|
sleep(0.1)
coll.insert(x)
end
p coll.count.to_s + " <single thread slow insert" #=> "3000 <single thread slow insert"
答案 0 :(得分:1)
您看到的错误是什么?您是否可以尝试将驱动程序设置为&#34; safe&#34;,以便您知道Mongo是否返回错误?
coll.insert(x, :safe => true)