MongoDB Schema Design - Real-time Chat
        Posted  
        
            by Nick
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Nick
        
        
        
        Published on 2010-05-29T21:02:38Z
        Indexed on 
            2010/05/29
            21:22 UTC
        
        
        Read the original article
        Hit count: 385
        
I'm starting a project which I think will be particularly suited to MongoDB due to the speed and scalability it affords.
The module I'm currently interested in is to do with real-time chat. If I was to do this in a traditional RDBMS I'd split it out into:
- Channel (A channel has many users)
 - User (A user has one channel but many messages)
 - Message (A message has a user)
 
The the purpose of this use case, I'd like to assume that there will be typically 5 channels active at one time, each handling at most 5 messages per second.
Specific queries that need to be fast:
- Fetch new messages (based on an bookmark, time stamp maybe, or an incrementing counter?)
 - Post a message to a channel
 - Verify that a user can post in a channel
 
Bearing in mind that the document limit with MongoDB is 4mb, how would you go about designing the schema? What would yours look like? Are there any gotchas I should watch out for?
© Stack Overflow or respective owner