1

Background Information

This is day one for me with couchbase. I've been reviewing the sample databases using the database console that comes with couchbase. Specifically, I've been playing with the "beer-sample" application to try to understand how to organize my database. It seems that they have two different types of documents - breweries or beers - and everything is just in one bucket.

For my personal application, I have the following data:

{
  "server_details": {
    "name": "testserver",
    "dns_name": "testserver.mydomain.net",
    "ipv4": "10.xx.xx.xx",
    "ipv6": "",
    "type": "webserver"
  },
  "server_status": {
    "up_to_date": true
  },
  "packages": {
    "package1": {
      "current_version": "x.x",
      "previous_version": "x.x",
      "last_updated_on": "2016-03-16",
      "play_id": "link to audit table"
    },
    "package2": {
      "current_version": "x.x",
      "previous_version": "x.x",
      "last_updated_on": "2016-03-16",
      "play_id": "link to audit table"
    }
  }
}

I have different server types such as webserver, appserver, dns server etc. So I'm planning to just use the same json object but change the "type" field.

Question

I also need to create some sort of a audit table that will show the history of when a package on a server was updated. I need to track things like:

  • execution date
  • script name
  • package1_version_b4_update
  • package1_version_after_update
  • server_dns_name

This is the json object I've come up with for this type of a document:

{
  "audit_details": {
    "script_name": "upgrade_all_mrts",
    "rt_ticket_number": "16123",
    "execution_date": "2016-03-16",
    "status": "success"
  },
  "affected_servers": {

    "server1": {     
      "package1":{
        "version_after_update": "x.x",
        "version_before_update": "x.x",
        "last_updated_on": "2016-03-16"
      },
      "package2": {
        "version_after_update": "x.x",
        "version_before_update": "x.x",
        "last_updated_on": "2016-03-16"
      }
   },
    "server2": {     
      "package1":{
        "version_after_update": "x.x",
        "version_before_update": "x.x",
        "last_updated_on": "2016-03-16"
      },
      "package2": {
        "version_after_update": "x.x",
        "version_before_update": "x.x",
        "last_updated_on": "2016-03-16"
      }
   }
  }
}

Would this be just another document with a completely different structure? or should i be putting it in another bucket? If it should all be in the same bucket, is the structure of the json object I'm proposing appropriate? Fundamentally, I guess my question is do you dump everything into one bucket as a collection of varied documents... and just make sure that the related documents have the same structure so that you can query them all at once?

Sorry for the remedial questions but I'm try to build a prototype on the fly ...while reading the docs. Any tips would be appreciated.

1

I'm also new to Couchbase but from what I've learned so far: generally, the reason you would want to use different buckets doesn't necessarily relate to the type of documents you want to put in them. That is, you may configure buckets to replicate differently, use XDCR, allocate memory differently, and so on. However, it's perfectly acceptable to have a wide variety of different document "types" in the same bucket.

It might be a good idea to give the different documents a "type" property, so that you can more easily query them.

So, for instance, in your examples, maybe the first one would have "type":"server", and the second one would have "type":"audit", and so on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.