jo / couchdb-best-practices

Collect best practices around the CouchDB universe.
https://jo.github.io/couchdb-best-practices/
Other
321 stars 33 forks source link

one to N relations example #75

Closed horacimacias closed 2 years ago

horacimacias commented 3 years ago

first of all thanks for these notes; there are very helpful.

Regarding the "one to N relations" example, I suggest making a minor update or adding some description of possible side effects.

In the example provided, where artist is "embedded" in the albums ids, between ":" separators, I'd suggest using this:

{
  "include_docs": true,
  "startkey": "artist:tom-waits:",
  "endkey": "artist:tom-waits:\ufff0"
}

instead of this (note there is no ":" after the value on startkey)

{
  "include_docs": true,
  "startkey": "artist:tom-waits",
  "endkey": "artist:tom-waits:\ufff0"
}

The current example would return albums for any artist whose name includes tom-waits; e.g. tom-waitson which is probably not what's intended. It may not be an extremely common scenario but since the artist is already put between ":" separators in the albums' ids, it may be a good idea to restrict startkey by that separator as well?

jo commented 2 years ago

fixed with https://github.com/jo/couchdb-best-practices/commit/9a462524e05143c4803ecf6dad73e1c3a68316cb

Thank you, @horacimacias