I recently had the chance to go to Riviera Dev, a fantastic developer conference taking place near the French Riviera. Couchbase sponsored the conference, we brought organic, local, goat milk ice-cream. People were happy, talks were interestings, SWAG was given out. It was an amazing conference.
When we sponsor conferences with such activities, we usually ask attendees if we can scan their badges to send them some Couchbase updates. So we did. And sometimes the information is easy to recover, sometimes it’s a bit tricky. Here, the QR code contained a VCard. Their purpose is to hold contact information, precious information – as you know, scans are the currency of conferences. It’s what allows us to come back the following year with even more ice cream.
Anyway, we ended up collecting a lot of VCards but it was hard to put them in the ubiquitous marketing format, CSV. So what do you do when you need to manipulate data? You use Couchbase Shell.
Couchbase Shell, Shell Yeah!
카우치베이스 셸 (cbsh) is a modern, productive, and fun shell for Couchbase Server and Capella (our cloud DBaaS). The source code and instructions to install it are available on the repo Readme.
I personally installed it by cloning and building it:
|
1 2 3 |
깃 복제 https://github.com/couchbaselabs/couchbase-shell cd 카우치베이스–shell cargo 설치 —경로 . |
You need to have the Rust toolchain installed, because Couchbase Shell is written in Rust, and based on my favorite shell, 누쉘.
Once installed, you can run it by typing cbsh. It will ask you to configure a Couchbase connection first. If you are using the Capella management interface, you will get all required information in the Connect tab.

Nushell <3 JSON
For the record, this is what my VCard looks like:
|
1 2 3 4 5 6 |
BEGIN:VCARD VERSION:2.1 N:DOGUIN;로랑;;; ORG:카우치베이스 EMAIL;INTERNET:laurent.doguin@카우치베이스.com END:VCARD |
There are plenty of node libraries to turn this to JSON, I have used vcard-json. So if I run node de vcard2json.js, I get a JSON array with all VCard content as a JSON object.
Which is great but how can this be manipulated easily? Cbsh being based on nushell, we get all the good things that come with it, like the from json command, or the where filter, and the JSON 선택. So let’s see how it would work step by step, with the structured data output, also courtesy of nushell:
|
1 2 3 4 5 |
👤 로랑 도귄 🏠 카펠라 < node vcard2json.자바스크립트 [{“이름”:{“surname”:“Doguin”,“이름”:“Laurent”,“additionalName”:“”,“prefix”:“”,“suffix”:“”},“organization”:“Couchbase”,“email”:[{“isDefault”:거짓,“valueInfo”:{},“value”:“laurentdoguin@couchbase.com”}]},{“이름”:{“surname”:“This”,“이름”:“Person”,“additionalName”:“”,“prefix”:“”,“suffix”:“”},“organization”:“DoesNotWorkAtCouchbase”,“email”:[{“isDefault”:거짓,“valueInfo”:{},“value”:“thiperson@notcouchbase.com”}]}] |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
👤 로랑 도귄 🏠 카펠라 < node vcard2json.자바스크립트 | 에서 JSON ╭───┬──────────────────────────────┬────────────────────────┬─────────────────────────────────────────────────────────────────────╮ │ # │ name │ organization │ email │ ├───┼──────────────────────────────┼────────────────────────┼─────────────────────────────────────────────────────────────────────┤ │ 0 │ ╭────────────────┬─────────╮ │ 카우치베이스 │ ╭───┬───────────┬───────────────────┬─────────────────────────────╮ │ │ │ │ surname │ 도귄 │ │ │ │ # │ isDefault │ valueInfo │ value │ │ │ │ │ 이름 │ 로랑 │ │ │ ├───┼───────────┼───────────────────┼─────────────────────────────┤ │ │ │ │ additionalName │ │ │ │ │ 0 │ 거짓 │ {record 0 fields} │ laurentdoguin@카우치베이스.com │ │ │ │ │ prefix │ │ │ │ ╰───┴───────────┴───────────────────┴─────────────────────────────╯ │ │ │ │ suffix │ │ │ │ │ │ │ ╰────────────────┴─────────╯ │ │ │ │ 1 │ ╭────────────────┬────────╮ │ DoesNotWorkAtCouchbase │ ╭───┬───────────┬───────────────────┬────────────────────────────╮ │ │ │ │ surname │ 이것 │ │ │ │ # │ isDefault │ valueInfo │ value │ │ │ │ │ 이름 │ Person │ │ │ ├───┼───────────┼───────────────────┼────────────────────────────┤ │ │ │ │ additionalName │ │ │ │ │ 0 │ 거짓 │ {record 0 fields} │ thiperson@notcouchbase.com │ │ │ │ │ prefix │ │ │ │ ╰───┴───────────┴───────────────────┴────────────────────────────╯ │ │ │ │ suffix │ │ │ │ │ │ │ ╰────────────────┴────────╯ │ │ │ ╰───┴──────────────────────────────┴────────────────────────┴─────────────────────────────────────────────────────────────────────╯ |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
👤 로랑 도귄 🏠 카펠라 < node vcard2json.자바스크립트 | 에서 JSON | where organization != ‘Couchbase’ ╭───┬─────────────────────────────┬────────────────────────┬────────────────────────────────────────────────────────────────────╮ │ # │ name │ organization │ email │ ├───┼─────────────────────────────┼────────────────────────┼────────────────────────────────────────────────────────────────────┤ │ 0 │ ╭────────────────┬────────╮ │ DoesNotWorkAtCouchbase │ ╭───┬───────────┬───────────────────┬────────────────────────────╮ │ │ │ │ surname │ 이것 │ │ │ │ # │ isDefault │ valueInfo │ value │ │ │ │ │ 이름 │ Person │ │ │ ├───┼───────────┼───────────────────┼────────────────────────────┤ │ │ │ │ additionalName │ │ │ │ │ 0 │ 거짓 │ {record 0 fields} │ thiperson@notcouchbase.com │ │ │ │ │ prefix │ │ │ │ ╰───┴───────────┴───────────────────┴────────────────────────────╯ │ │ │ │ suffix │ │ │ │ │ │ │ ╰────────────────┴────────╯ │ │ │ ╰───┴─────────────────────────────┴────────────────────────┴────────────────────────────────────────────────────────────────────╯ |
|
1 2 3 4 5 6 7 |
👤 로랑 도귄 🏠 카펠라 < node vcard2json.자바스크립트 | 에서 JSON | where organization != ‘Couchbase’ | 선택 이름.이름 이름.surname organization 이메일.0.value ╭───┬───────────┬──────────────┬────────────────────────┬────────────────────────────╮ │ # │ name_name │ name_surname │ organization │ email_0_value │ ├───┼───────────┼──────────────┼────────────────────────┼────────────────────────────┤ │ 0 │ Person │ 이것 │ DoesNotWorkAtCouchbase │ thiperson@notcouchbase.com │ ╰───┴───────────┴──────────────┴────────────────────────┴────────────────────────────╯ |
Now that the data is ready and cleaned-up, what can I do with it ? I could write this to a CSV file like this:
|
1 |
< node vcard2json.자바스크립트 | 에서 JSON | where organization != ‘Couchbase’ | 선택 이름.이름 이름.surname organization 이메일.0.value | -로 csv| 저장 contacts.csv |
I could also write it to Couchbase. I have my credential all set already. The first command chooses the bucket and default scope and collection. The second one iterates through the JSON array, generates a random UUID, wraps the content under a content column and adds an ID column with the generated UUID, then inserts the result in Couchbase.
|
1 2 3 |
👤 로랑 도귄 🏠 카펠라 < 씨비–환경 양동이 vcard |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
👤 로랑 도귄 🏠 카펠라 안으로 구름 vcard._default._default < node vcard2json.자바스크립트 | 에서 JSON | where organization != ‘Couchbase’ |선택 이름.이름 이름.surname organization 이메일.0.value |rename 이름 lastname organization 이메일 | 각각 { |그것| 하다 UUID = {무작위의 UUID}; $그것 | 포장하다 콘텐츠| 삽입하다 아이디& ; $UUID& ; | 의사 업서트& ; } ╭───┬───────────────────────────────────────────────────────────╮ │ 0 │ ╭───┬───────────┬─────────┬────────┬──────────┬─────────╮ │ │ │ │ # │ processed │ success │ failed │ failures │ cluster │ │ │ │ ├───┼───────────┼─────────┼────────┼──────────┼─────────┤ │ │ │ │ 0 │ 1 │ 1 │ 0 │ │ 카펠라 │ │ │ │ ╰───┴───────────┴─────────┴────────┴──────────┴─────────╯ │ │ 1 │ ╭───┬───────────┬─────────┬────────┬──────────┬─────────╮ │ │ │ │ # │ processed │ success │ failed │ failures │ cluster │ │ │ │ ├───┼───────────┼─────────┼────────┼──────────┼─────────┤ │ │ │ │ 0 │ 1 │ 1 │ 0 │ │ 카펠라 │ │ │ │ ╰───┴───────────┴─────────┴────────┴──────────┴─────────╯ │ ╰───┴───────────────────────────────────────────────────────────╯ |
And just to make sure it’s working, the data can be queried with SQL++ directly:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
👤 로랑 도귄 🏠 카펠라 안으로 구름 vcard._default._default < 질의 “SELECT * from `vcard`” ╭───┬────────────────────────────────────────────────┬─────────╮ │ # │ vcard │ cluster │ ├───┼────────────────────────────────────────────────┼─────────┤ │ 0 │ ╭──────────────┬─────────────────────────────╮ │ 카펠라 │ │ │ │ 이름 │ Person1 │ │ │ │ │ │ lastname │ LastNa │ │ │ │ │ │ organization │ Organisat │ │ │ │ │ │ 이메일 │ person1lastna@카우치베이스.com │ │ │ │ │ ╰──────────────┴─────────────────────────────╯ │ │ │ 1 │ ╭──────────────┬────────────────────────────╮ │ 카펠라 │ │ │ │ 이름 │ Person │ │ │ │ │ │ lastname │ 이것 │ │ │ │ │ │ organization │ DoesNotWorkAtCouchbase │ │ │ │ │ │ 이메일 │ thiperson@notcouchbase.com │ │ │ │ │ ╰──────────────┴────────────────────────────╯ │ │ ╰───┴────────────────────────────────────────────────┴─────────╯ |
So there you are, a practical example of using Couchbase Shell to manipulate Data, transform it and import it to Couchabse. But there are plenty of other uses for it! What’s your favorite?

댓글 남기기
댓글을 달기 위해서는 로그인해야합니다.