which is the best way to structure the data on couchdb?

design two different structures for my couch database, I want to know which one suits me best.

document by course:

    {                   
  "_id": "e11b862c9939f9d0de39f3aa28036c96",
  "_rev": "4-e1245399d2f074ef5710d6bcbb0aa7f7",
  "nombre": "JavaScript",
  "descripcion": "curso basico de javascript",
  "horas": 50,
  "costo": 500000,
  "modalidades": [
    {
      "nombre": "online",
      "descripcion": "cursos en linea",
      "descuentos": [
        {
          "descuento": 0.2,
          "fecha caducidad": "2017-11-20"
        },
        {
          "descuento": 0.1,
          "fecha caducidad": "2017 - 12 - 30 "
        }
      ]
    },
    {
      "nombre": "privada",
      "descripcion": "cursos privados",
      "descuentos": [
        {
          "descuento": 0.2,
          "fecha caducidad": "2017-11-20"
        }
      ]
    }
  ]

I make a unique document where I keep the courses, the costs of the courses, and the discounts of each course depending on the modality, I want to know which of the two forms is more useful to administer

{
  "_id": "e11b862c9939f9d0de39f3aa28034b9e",
  "_rev": "3-87278a7404c9f458be9beec1808aafb7",
  "cursos": [
    {
      "nombre": "Javascript",
      "descripcion": "curso basico de javascript",
      "horas": 50,
      "costo": 500000,
      "modalidad": [
        {
          "nombre": "online",
          "descripcion": "cursos en linea",
          "descuentos": [
            {
              "descuento": 0.2,
              "fecha caducidad": "2017-12-20"
            }
          ]
        },
        {
          "nombre": "privada",
          "descripcion": "cursos privados",
          "descuentos": [
            {
              "descuento": 0.15,
              "fecha caducidad": "2017-12-20"
            }
          ]
        }
      ]
    },
    {
      "nombre": "HTML5",
      "descripcion": "curso basico de HTML5",
      "horas": 60,
      "costo": 400000,
      "modalidad": [
        {
          "nombre": "online",
          "descripcion": "cursos en linea",
          "descuentos": [
            {
              "descuento": 0.3,
              "fecha caducidad": "2017-12-20"
            }
          ]
        },
        {
          "nombre": "privada",
          "descripcion": "cursos privados",
          "descuentos": [
            {
              "descuento": 0.2,
              "fecha caducidad": "2017-12-20"
            }
          ]
        }
      ]
    }
  ]
}

Upvotes: 0

Views: 101

Answers (1)

xpqz
xpqz

Reputation: 3737

As you've not provided any clues on how you intend to actually use the data, it's hard to offer more than generic advice. However...

It's typically easier to get good performance out of CouchDB/Cloudant following the first approach -- a separate, small document for each course, rather than one large document holding data about all courses. It depends on the usage patterns your application will exhibit. I would guess that the course data will change only infrequently (good for performance, and low likelihood of conflicts), and that the application will mainly need access to course data on a per-course basis.

I would go for the first approach, and construct a view to provide access to all courses by name. That way you would never need to load all course data to simply expose data about your JavaScript course, for example.

Upvotes: 1

Related Questions