As an alternative to @inspired's answer (which translates your schema straight to MongoDB and models via document references), it might be easier to embed data into the user document.
If you choose to embed, it would look 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
}, {
// another item, omitted for brevity
} ] // end items
}, {
// another wallet, omitted for brevity again
} ] // end wallets
} // end user
This allows easy accessing of f.ex. transactions via
user.wallets[0].items[1].transactions[0].whatever
Note that not all transactions have to have the same fields. Here, transactions[1]
has a field named another_transaction
. Note also that JSON does not allow comments (they are for understanding better).
A limitation of this is the 16MB document maximum size of MongoDB.
If each user amasses more than 16 MB of total data, you will probably implement @inspired's answer or something in between, where you store (for example) everything up to items inside the user, together with a list of transaction_id
s. But it depends on how many transactions you expect and how often they are going to change.
For the question of embedding vs referencing, see MongoDB relationships: embed or reference?.