meteor - from relation table to mongodb -


i'm trying create mongodb design (but i'm new @ mongo) based on relation database schema.

my question is: how far denormalize schema?:

-users --wallets[field1,field2] ---items[field1,field2] ----transactions[field1,field2] --.... 

users -> linked lot of tables.
wallets -> user can have more wallets.
items -> wallet can have more items(the field values of items not regulary change).
transactions -> item can have more transactions.
idea to:

  1. split users in document
  2. group wallets , transactions (create reference user_id (at wallet level) , item_id (on transaction level)) in document
  3. items in document

will right approach?

as why mongodb: because i'm creating meteor app.

as alternative @inspired's answer (which translates schema straight mongodb , models via document references), might easier embed data user document.

if choose embed, like:

{ name: 'username',   id: objectid("512512a5d86041c7dca81914"),   wallets: [ {     wallet_name: 'its_name_if_required',     field_one: 'its_content',     field_two: 'its_content',     items: [ {       item_field_one: 'content_item_1',       item_field_one: 'other_content_item_1',       transactions: [ {         whatever: 1,         a_transaction: 'some string',         contains: new date()       }, {         whatever: 1,         another_transaction: 'some string',         contains: new date()       } ] // end transactions     }, {        // item, omitted brevity     } ] // end items   }, {     // wallet, omitted brevity again   } ] // end wallets } // end user 

this allows easy accessing of f.ex. transactions via

user.wallets[0].items[1].transactions[0].whatever 

note not transactions have to have same fields. here, transactions[1] has field named another_transaction. note json not allow comments (they understanding better).

a limitation of 16mb document maximum size of mongodb.

if each user amasses more 16 mb of total data, implement @inspired's answer or in between, store (for example) items inside user, list of transaction_ids. it depends on how many transactions expect , how going change.

for question of embedding vs referencing, see mongodb relationships: embed or reference?.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -