CouchDB Database Structure - Best Practice

As a newbie to CouchDB, I just wanted to discuss best practices for structuring databases and documents. My experience is with MySQL, so we are still trying to get a handle to the document-driven databases.

To highlight the system, we have several clients, each of which has access to a separate website with separate data. The data of each client will be divided into its own database. Each database will constantly insert data (every 5 minutes, at least for a year) to record events. A new document is created every 5 minutes with a time stamp and value. We also need to keep some information about the client, which is the only document that is never updated (if so, very rarely).

The following is an example of what a single client database looks like ...

{
    "_id": "client_info",
    "name": "Client Name",
    "role": "admin",
    ....
},
{
    "_id": "1199145600",
    "alert_1_value": 0.150
    "alert_2_value": 1.030
    "alert_3_value": 12.500
    ...
    ...
},
{
    "_id": "1199145900",
    "alert_1_value": 0.150
    "alert_2_value": 1.030
    "alert_3_value": 12.500
    ...
    ...
},
{
    "_id": "1199146200",
    "alert_1_value": 0.150
    "alert_2_value": 1.030
    "alert_3_value": 12.500
    ...
    ...
},
etc...literally millions more of these every 5 minutes...

My question is, is such a structure correct? I understand that CouchDB is a flat database, but there will be literally millions of timestamp / value documents in the database. I may just be picky, but it seems a little disorganized to me.

Thank!

+5
source share
1 answer

Use a timestamp as your identifier, if guaranteed to be unique. This greatly improves the couch's ability to support b-tree for things such as creating and maintaining views, as well as documents, as well as saving space len([_id]).

( ) b-. ( SQL-) doc , .

CouchDB. , , . , , SQL, " ", , b- . .

, CouchDB: - , (.. ) - , , -.

, . , () erlang; https://github.com/apache/couchdb/blob/trunk/src/couchdb/couch_query_servers.erl#L172-205, , .

+3

All Articles