想要把 Json 字符串直接存入 mongodb,但是报如下错误:
/home/tim-tang/.rvm/gems/[email protected]/gems/mongo-1.6.2/lib/mongo/collection.rb:308:in
save': undefined method has_key?' for #<String:0x96ffc80> (NoMethodError)
具体代码如下: `#encoding:utf-8 require "crack" require "json" require "mongo"
myXML = Crack::XML.parse(File.read("/home/tim-tang/OFBProductCategory1.xml")) myJSON = myXML.to_json puts myJSON
connection = Mongo::Connection.new("localhost", 27017) db = connection.db("tim-db") coll = db.collection("products") coll.save(myJSON)`
好像是无法产生_id,知道的请指点下,谢谢!