require 'mongo' require "fileutils" @conn = Mongo::Connection.new("localhost", 30000) @conn.database_names.each { |name| puts name } @db = @conn['sample_db'] @coll = @db['test'] doc = {"name" => "MongoDB", "type" => "database", "count" => 1, "info" => {"x" => 203, "y" => '102'}} #@coll.insert(doc) File.open("E:\\eng_00\\1.jpg", 'rb') {|fin| fileText = fin.read 10000.times do |i| puts(i) @coll.insert({'LI' => i+30000, 'G' => BSON::Binary.new(fileText)}) end } puts "There are #{@coll.count} records. Here they are:" @coll.find.each { |doc| puts doc.inspect }
利用ruby 向 mongodb 插入 二进制内容(图像文件)
猜你喜欢
转载自huaxiamian.iteye.com/blog/1402444
今日推荐
周排行