I am breaking my mind up thinking about a good document structure for handling a message app.
I basically need three (or four) types of objects:
- The user (username, email, password, etc.)
- The contacts list (containing different contacts or contacts groups)
- The conversation (a conversation is a collection of messages between some persons)
- The message (contains the message body, some timestamp and the creator.)
My idea was to embed the contacts into the user document and to embed the messages in a conversation document:
1. User
{
username: 'dev.puS',
usernameCanonical: 'dev.pus', // used for unique constraints
email: 'developement.pus@gmail.com,
emailCanonical: 'developement.pus@gmail.com,
salt: 'some hash',
password: 'hash with salt',
logs: { last_login: 12.06.2008, last_password_reset: 04.03.2007 },
state: { online: true, available: false },
contacts: [ user_id1, user_id2, user_id3 ]
}
2. Conversation
{
members: [ user_id1, user_id2 ],
messages: [
{ author: user_2, body: 'Hi what's up' },
{ author: user_1, body: 'Nothing out here :(' },
{ author: user_2, body: 'Whanna ask some question on stackoverflow' },
{ author: user_1, body: 'Okay, lets go' }
]
}
What do you think about this schema?
I think it would be better to keep them seperated (so each document for it's own) because each document has different update frequency. But I really don't have any experience about it so it would be good to hear some advices :)
Regards