Reputation: 25
Good morning!
I want to use couchdb/pouchdb for my pwa that I currently work on.
In my project I want to to store "Projects", in a "Project" I want to store the project-title and "Chapters", in a "Chapter" I want to store the chapter-title and "Scenes", a "Scene" contains contain text.
What schema would make the most sense and performance?
Right now I think about a plan like this:
Since I only have SQL experience and never used document based databases before, I dont really know how to put a structure that makes sense.
Do I store documents inside documents to have a schema that looks exactly like above or do I create a database for each component(Projects,Chapters,Scenes)?
Upvotes: 1
Views: 567
Reputation: 3737
You have several options.
Which one is the best depends on the likely total size, and how each of these components change. CouchDB works best with small documents (kilobytes). As you can only update whole documents, changing bits inside lists or inside objects in larger documents quickly become inefficient, and potentially generating update conflicts.
The second suggestion above will scale better, but (currently; see link below) lacks the convenience of being able to pull out everything about a project with a single API call. You can use the id field to great effect:
{
"_id": "project1:toplevel",
"type": "project",
"title": "Project 1"
}
{
"_id": "project1:chapter1",
"type": "chapter",
"title": "Project 1, chapter 1"
}
{
"_id": "project1:chapter1#scene1",
"type": "scene",
"title": "Project 1, chapter 1, scene 1"
}
In a "landing soon" version of CouchDB this id format can be used to leverage so-called partitioned databases that would be a great fit here. You can read blog posts about it here:
https://blog.cloudant.com/2019/03/05/Partition-Databases-Introduction.html
Upvotes: 1