Import CSV file into Couchbase

I have a issue importing csv files into couchbase server.

Example:
I have a csv file with 3 rows and 4 columns like c1, c2, c3, c4.
Now I want to import csv into couchbase sample bucket as below.

type: vehicle as below:
[
{
“sample”: {
“c1”: “test”,
“c3”: “t1”,
“type”: “vehicle”
},
{
“c1”: “test 1”,
“c3”: “t2”,
“type”: “vehicle”
},
{
“c1”: “test 2”,
“c3”: “t3”,
“type”: “vehicle”
}
}
]

type: customer as below:
[
{
“sample”: {
“c2”: “testing”,
“c4”: “t11”,
“type”: “customer”
},
{
“c2”: “testing 1”,
“c4”: “t22”,
“type”: “customer”
},
{
“c2”: “testing 2”,
“c4”: “t33”,
“type”: “customer”
}
}
]

I tried with cbimport but no luck. With cbimport we can import all columns into a bucket.

Please assit. Thank you.

Looks like your JSON is invalid, please try some online validator to double check it. could you also post the command line you are using?

Thanks deniswsrosa for your quick response.

here is the updated json formats.

csv file with 3 rows and 4 columns like c1, c2, c3, c4.

type: vehicle as below:
[{
“sample”: {
“c1”: “test”,
“c3”: “t1”,
“type”: “vehicle”
}
},
{
“sample”: {
“c1”: “test 1”,
“c3”: “t2”,
“type”: “vehicle”
}
},
{
“sample”: {
“c1”: “test 2”,
“c3”: “t3”,
“type”: “vehicle”
}
}
]

type: customer as below:
[{
“sample”: {
“c2”: “testing”,
“c4”: “t11”,
“type”: “customer”
}
},
{
“sample”: {
“c2”: “testing 1”,
“c4”: “t22”,
“type”: “customer”
}
},
{
“sample”: {
“c2”: “testing 2”,
“c4”: “t33”,
“type”: “customer”
}
}
]

and i am using windows cmd. C:\Program Files\Couchbase\Server\bin>cbimport csv -c couchbase://localhost -u Administrator -p password -b sample -d file:///data/CSV/sample.csv -g key::%id%

Please advise.

@deniswsrosa

Any suggestions on above query?

Here is a working example:

[

{
    "id": 123,
	"sample": {
        
		"c2": "testing",
		"c4": "t11",
		"type": "customer"
	}
},
{
    "id": 456,
	"sample": {
        "id": 456,
		"c2": "testing 1",
		"c4": "t22",
		"type": "customer"
	}
},
{
    "id": 789,
	"sample": {
        
		"c2": "testing 2",
		"c4": "t33",
		"type": "customer"
	}
}

./cbimport json -c couchbase://127.0.0.1 -u Administrator -p password -b sample --d file:///data/CSV/sample.csv -f list -g key::%id% -t 4 ]

A few note: in your command, you are specifying to use the field “id” (-g key::%id%) as the key, but there is no field named “id” in your document.

btw, in the next release of couchbase they will fix they will print the error after you execute cbimport, the fix is already merged.

follow me on twitter @deniswsrosa

Thanks @deniswsrosa.

I am looking for specifying few columns from csv file when I use cbimport.

Much appreciated your help.

Thank you.