问题
I didn't see any way to insert documents in bulk using Couchbase Python client. Any example of how to insert documents in bulk using REST api?
回答1:
I am answering here for Couchbase only, as you probably know they are 2 different project with different features.
The Python SDK does not have a way to bulk load the data.
So to do that you can use: - the standard set/add methods - the cbdocloader command line tool that allows you to inject data from the file system into Couchbase Server see : http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-admin-cmdline-cbdocloader.html
回答2:
I used a CURL script with the Sync Server RESTful API Example JSON as 400001.json file belonging to sync user1.
{"type": "task-list", "name": "Order400001", "owner": "user1", "_id" : "user1.S100400001" , "Order": { "OrderID": "S100400001", "Status": "In Transit", "Customer": "My Customer", "DateSubmitted": "12/21/2017", "PO": "123455", "SoldToAccount": "0001122333", "ShipToAccount": "0001122333", "Items": [{ "ItemID": "XXX", "ItemStatus": "In Transit", "ItemQty": "2", "ItemPrice": "1500", "ItemDescription": "MODULE XXX US CAN" }, { "ItemID": "XXXG", "ItemStatus": "In Transit", "ItemQty": "2", "ItemPrice": "15000", "ItemDescription": "MODULE XXX US CAN (GOLD)" } ] } }
Then the script like this
curl -X POST "http://user:password@MyCouchBaseSyncServerHost:4984/orders/" -H "accept: application/json" -H "Content-Type: application/json" -H "Authorization: Basic {your key here}" -d @401000.json
来源:https://stackoverflow.com/questions/14742608/how-to-insert-a-documents-in-bulk-in-couchbase