카우치베이스 카펠라

Using Couchbase Shell to Transform and Write Data

5 분 읽기

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!

Couchbase Shell (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:

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:

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 select. So let’s see how it would work step by step, with the structured data output, also courtesy of nushell:

 

 

 

 

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:

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.

 

And just to make sure it’s working, the data can be queried with SQL++ directly:

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?



이 기사 공유하기

작가

로랑은 파리에 사는 찌질한 매니아 기질이 있는 헤비메탈 마니아입니다. 그는 주로 자바(Java)로 코드를 작성하고 AsciiDoc으로 구조화된 텍스트를 작성하며, 데이터, 리액티브 프로그래밍 및 기타 유행어 같은 주제에 대해 자주 이야기합니다. 그는 또한 Clever Cloud와 Nuxeo의 전직 개발자 애드보케이트로 활동하며 해당 커뮤니티가 더 크고 강하게 성장하도록 시간과 전문 지식을 쏟아부었습니다. 현재는 카우치베이스(Couchbase)에서 개발자 관계(Developer Relations)를 총괄하고 있습니다.

댓글 남기기

카우치베이스 카펠라를 시작할 준비가 되셨나요?

개발 시작하기

NoSQL을 탐색하고, 리소스를 찾아보고, 튜토리얼을 시작하려면 개발자 포털을 확인하세요.

카펠라 프리 사용하기

단 몇 번의 클릭으로 카우치베이스(Couchbase)를 직접 체험해 보세요. Capella DBaaS는 시작하기 가장 쉽고 빠른 방법입니다.

연락해

Couchbase 제품군에 대해 더 알고 싶으신가요? 저희가 도와드리겠습니다.