[GH-ISSUE #75] one to N relations example #62

Closed
opened 2026-03-31 22:01:54 -06:00 by gitea-mirror · 1 comment
Owner

Originally created by @horacimacias on GitHub (Apr 12, 2021).
Original GitHub issue: https://github.com/jo/couchdb-best-practices/issues/75

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?

Originally created by @horacimacias on GitHub (Apr 12, 2021). Original GitHub issue: https://github.com/jo/couchdb-best-practices/issues/75 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: ```json { "include_docs": true, "startkey": "artist:tom-waits:", "endkey": "artist:tom-waits:\ufff0" } ``` instead of this (note there is no ":" after the value on `startkey`) ```json { "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?
Author
Owner

@jo commented on GitHub (Apr 3, 2022):

fixed with 9a462524e0

Thank you, @horacimacias

<!-- gh-comment-id:1086857137 --> @jo commented on GitHub (Apr 3, 2022): fixed with https://github.com/jo/couchdb-best-practices/commit/9a462524e05143c4803ecf6dad73e1c3a68316cb Thank you, @horacimacias
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/couchdb-best-practices#62
No description provided.