When importing relational data in to Couchbase , should each table corresponds to a bucket. I ask because older documentation recommends minimizing the number of buckets and keep multiple document types together and use a type attribute to differentiate between. The tutorials I’ve see for using N1QL have one bucket for each entity which makes joining documents easier.
Imagen importing employee and department data when the employee has a dept_id foreign key. Should employees and departments be in separate buckets? Or should I put them in the same bucket and give them type attributes with keys like emp_id_1 and dept_id_2 which doesn’t seem to work as well with N1QL.
While it is possible to simply import relational rows as Couchbase documents, it is often better to remodel the data to take advantage of the nesting and arrays that JSON documents permit. Joins are always expensive, and if you have common queries that rely upon joins, the queries will likely be faster if the relevant documents are merged.
I am working with a data model that has teams, stadiums, and players. What would be a good way to model this in Couchbase. nesting a stadium inside of each team and a team inside each player seems like it would use a lot of space.
@bfwarner -Yes, it sounds like your particular data is not likely to benefit from nesting. It all depends on the cardinality of relationships and the kinds of queries you’ll be running. Some situations, such as customers with a small, variable number of mailing addresses or credit cards, nesting that data doesn’t increase data size much and can avoid joins.
For the best performance, make sure that when one data type refers to another, use the document id. E.g., if a player is only on one team, have the ‘team’ field of the player contain the document id of the team. Document ids are the fastest way to retrieve a document.