Hello,
I am just starting with CouchBase and i would like your input on whats the best choice between embedding and referring document fields.
My use case is as follows: i am building a web app where notifications are triggered (a script produces these notifications and stores them to CB once every 24 hours) and presented to a publisher. A publisher may have many apps, and the apps themselves contain a lot of notifications.
A sample of the queries i would like to do internally are:
- “Bring me all notifications from this publisher”
- “List all notifications by notification_type”
- “Bring me all notifications for this app”
- “Bring me notifications for this specific timedate”
The structure of the doc the way i am viewing it is
Key:
n::<'notification_id'>
Doc Value:
{
publisher : 'stelios',
appid : 4,
time_created: '2015-10-9',
notification_type: 5,
...//more data
}
Should i embed all the properties i want in a single document, or separate them into a document sets for notifications, a document set for the publishers and a document set for the apps. I have a read-heavy workload and inconsistencies are not an issue since a user cant update a field of a notification.
i.e refering the notification in a separate publisher doc:
key:
p::<'publisher_id'>
Doc Value:
{
notification_ids: []
}
First question: Can i use the lookup pattern to perform the first 3 queries:
client.add('n::1', notification_doc1);
client.add('n::2', notification_doc2);
client.set('p::stelios', {
notification_ids: ['n::1', 'n::2']
});
client.set('a::4', {
notification_ids: ['n::1', 'n::2']
});
This way I can first query for a publisher and get the notifications id and then with a multi get I can fetch all of their notifications.
Also, is there a way to have flexibility on my queries based on timeframe (e.g get notifications per day, per hour, etc) or should i use views to expose the timestamp?
I used these resources for my research:
http://docs.couchbase.com/developer/dev-guide-3.0/doc-design-considerations.html
http://blog.couchbase.com/data-modelling-when-embed-or-refer
If you have any other material in mind i could consult please refer me to it.