I am attempting to import a json file into a Cloudant database. As someone who has very little knowledge on the topic this simple task has seemed to be very difficult. The video Importing JSON documents into a NoSQL DB in Bluemix using NoSQLimport seems to have do what I am trying to accomplish, however, I am not able to follow along with what is being done. Can someone explain the process a little bit more clearly?
One way is to use the _bulk_docs
endpoint. For example, create a file test.json
:
cat test.json
{
"docs": [
{
"name": "stefan",
"city": "bristol"
},
{
"name": "bob",
"city": "london"
}
]
}
You can now upload that file using curl
with each item in the docs
array as a Cloudant document:
curl -XPOST 'https://U:P@ACCT.cloudant.com/DB/_bulk_docs' \
-Hcontent-type:application/json -d @test.json
[
{
"ok":true,
"id":"2fd7e2584e58da82703350669f3b065c",
"rev":"1-acf5731c338adbd23311f7513ae2c2c2"
},
{
"ok":true,
"id":"2fd7e2584e58da82703350669f3b07aa",
"rev":"1-3a1c83440d0c91fcdd095e286fea9fb5"
}
]
If you open the Cloudant dashboard you should now be able to see the documents you uploaded.