dongya2029 2014-10-22 08:58
浏览 87
已采纳

用php将文件大量插入couchbase数据库 - 如何?

I am experimenting actually a little bit with couchbase server.

I have tried to read a mysql database table, build a document from each data row and then inserting the document with an id which I generate with

uniqid('table_name'); 

via cUrl, method is POST.

This so far works pretty good, until the script has inserted roundabout 7050 documents. Then an exception is thrown -> "No buffer space".

Until now I was not able to fix this, so I decided to collect i.e. 50 rows of data build a json_encode(d) string and POST it again via cUrl.

This worked so far if I don't set the id - but I can't figure out how to set the id of the inserted documents.

Actually I try to send my documents in a format like this:

{"docs": {
   "_id": {
          "geodata_de_54476f7e6adc57.14196038": {
              "table": "geodata_de",
              "country": "DE",
              "postal_code": "01945",
              "place_name": "Lindenau",
              "state_name": "Brandenburg",
              "state_code": "BB",
              "province_name": "",
              "province_code": "00",
              "community_name": "Oberspreewald-Lausitz",
              "community_code": "12066",
              "lat": "51.4",
              "lng": "13.7333",
              "Xco": "3861.1",
              "Yco": "943.614",
              "Zco": "4979.07"
           } 
       },  ...
   }

}

but this just inserts ONE document with the above object.

Maybe there is someone here who can point me the right direction.

  • 写回答

1条回答 默认 最新

  • dragon19720808 2014-10-23 19:05
    关注

    I would use the Couchbase PHP SDK to insert these documents instead of using curl. http://docs.couchbase.com/developer/php-2.0/storing.html

    Also for CB, you do not have to set the ID in the document itself. it depends. I might take a look at instead using the ID you have in your example ("geodata_de_54476f7e6adc57.14196038") and put it as the key for the object in Couchbase. Then you do not necessarily need the _id. The key in Couchbase can be up to 250 bytes of data and you can make it meaningful to your application so you can do lookup by key extremely fast.

    Another option is, if you wrote your docs to the filesystem, you could also use cbdocloader utility which is specifically for bulk loading docs. If you are on linux it is in /opt/couchbase/bin/tools/cbdocloader.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大