我想在沙发底座上做些大面积的插入。我试图在SO和google上搜索示例,但没有得到任何线索。有人说这是不可能的。在
How to insert a documents in bulk in Couchbase?
但我想这个问题是3年前提的。我搜索,如果我从下面给出的链接正确理解,它可以批量插入文档。在
https://developer.couchbase.com/documentation/server/current/sdk/batching-operations.html
https://pythonhosted.org/couchbase/api/couchbase.html#batch-operation-pipeline
下面是我要在couchbase中实现大容量插入的代码
import time
import csv
from couchbase import Couchbase
from couchbase.bucket import Bucket
from couchbase.exceptions import CouchbaseError
c = Bucket('couchbase://localhost/bulk-load')
from couchbase.exceptions import CouchbaseTransientError
BYTES_PER_BATCH = 1024 * 256 # 256K
with open('/home/royshah/Desktop/bulk_try/roy.csv') as csvfile:
lines = csvfile.readlines()[4:]
for k, line in enumerate(lines):
data_tmp = line.strip().split(',')
strDate = data_tmp[0].replace("\"", "")
timerecord = datetime.datetime.strptime(strDate,
'%Y-%m-%d %H:%M:%S.%f')
microsecs = timerecord.microsecond
strDate = "\"" + strDate + "\""
ts = calendar.timegm(timerecord.timetuple())*1000000 + microsecs
datastore = [ts] + data_tmp[1:]
stre = {'col1 ': datastore[1], # I am making key-values on the fly from csv file
'col2': datastore[2],
'col3': datastore[3],
'col4': datastore[4],
'col5': datastore[5],
'col6': datastore[6]}
cb.upsert(str(datastore[0]), (stre)) # datastore[0] is used as document
id and (stre) is used as key-value to be
inserted for respective id.
在cb.upsert公司(str(数据存储[0]),(stre)) 正在进行单次插入,我想让它批量插入,以使它更快。我不知道如何在couchbase中进行批量插入。我找到了这个例子,但不知道如何实现。在
https://developer.couchbase.com/documentation/server/current/sdk/batching-operations.html
如果有人指出couchbase中批量加载的一些示例,或者帮助我弄清楚如何通过代码进行批量插入。我真的很感激。谢谢你的任何想法或帮助。在
我试图将来自docs的示例改编为您的用例。你可能需要改变一两个细节,但你应该明白。在
相关问题 更多 >
编程相关推荐