开发者

capped collection mongodb

开发者 https://www.devze.com 2023-02-03 19:29 出处:网络
I have issues with mongoDB. Currently i\'m working with Ruby mongodb drivers and there r some strange things r going on:

I have issues with mongoDB. Currently i'm working with Ruby mongodb drivers and there r some strange things r going on:

i need to insert 20 documents in the capped collection but when i write the following code, it inserts only 3 docs and i can't get what's going on:

coll = db.create_collection("test",:capped => true, :max=>20)
1024.times{@pad_string +=" "}

20.times{coll.insert({
             :HostName    => @hostname,
             :CommandLine => @cmdline,
             :Pid         => "1111",
             :BlockName   => @blockname,
             :ExitCode    => 0,
             :StartTime   => Time.now,
             :EndTime     => Time.utc(2000,"jan",1,00,00,00),
             :StdErr      => @pad_string,
             :Stdout      => @pad_string}
         )}
开发者_如何学C

actually the point is that i insert @pad_string with 1024 preallocated spaces. As soon as i do that before inserting 1024.times{@pad_string +=" "}, it inserts only 3 docs maximum.


When you cap a collection based on the number of objects you also have to cap it based on size - I wonder what size the ruby driver is sending down.

try this:

coll = db.create_collection("test",:capped => true, :size=>100000, :max=>20)

Then tweak the size to whatever works for you (it's in bytes).

0

精彩评论

暂无评论...
验证码 换一张
取 消