Kenneb15
Kenneb15

Reputation: 3

Append sensor data into document in Couchbase database

We are a group of people writing a bachelor-project about storing sensor data into a noSQL-database, and we have chosen couchbase for this.

We want to store quite a few data in the same document, one document per day, per sensor, and we want to append new sensor data witch comes in every minute. But unforunatly, we are not able to append new data into existing document without overwriting the existing data.

The structure for the documents is:

DocumentID: Sensor + date, ie: KitchenTemperature20180227
{
  "topic": "Kitchen/Temp",
  "type": "temperature",
  "unit": "DegC"
  "20180227130400": [
    {
      "data": "24"
    }
  ],
..............
  "20180227130500": [
    {
      "data": "25"
    }
  ],
}

We are all new to couchbase and NoSql-databases, but eager to learn and understand how we the best way should implemet this. We've tried upsert, insert and update commands, but they all overwrite the existing document or won't execute because the document already exists. As you can see, we have some top-level information, like topic, type, unit. The rest should be data coming in every minute and appended to the existing document.

Help on how to proceed would be very appriciated.

Best regards, Kenneth

Upvotes: 0

Views: 46

Answers (1)

Hod
Hod

Reputation: 2286

In this case you can use the subdocument API. This allows you to modify portions of a document based on a "path". This image gives the idea for getting a subdocument.

enter image description here

You can mutate subdocuments as well. Look at the subdocument API documentation for Couchbase. There are also blog posts that go through examples in Java and Go on the Couchbase blog site.

Upvotes: 0

Related Questions