Reputation: 2406
Why does Mongo sometimes write and sometimes doesn't? The code can probably give a better idea of what I am talking about:
Note:
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"
Upvotes: 0
Views: 95
Reputation: 24007
what's the error you're seeing? Can you try setting the driver's write to "safe", so you'll know whether Mongo returned an error or not?
coll.insert(x, :safe => true)
Upvotes: 1