many to many - MongoDB Few-To-Few Association -


this follow-up question on mongodb : limit between "few" , "many"?.

i come relational database world , working on new nosql project mongodb.

edit: working on project rails, , decided move meteor prototyping, requires use mongodb. providing below information explain had come in terms of database schema when working on rails version of project.

this project based on following collections:

user   firstname   lastname   emailaddress   password       calendar   title  role   userid   calendarid  post   calendarid   date   time   focus   format   blogtitle   longcopy   shortcopy   link   hashtag   media   promotion   target   approval   comment 

a user able create , manage several calendars , calendar allow several users collaborate.

i believe few-to-few (not many-to-many) association since:

  • a user should not have more couple dozens calendars
  • a calendar should not have more dozen users

the access pattern following:

  • a user log in, , automatically presented list of calendars.
  • the main action of user choose calendar , edit content (crud posts within given calendar).
  • sometimes, not within every session, user need access , crud list of users belonging 1 of calendars.

what best way structure such project mongodb?

one of design pattern storing calendar associated each other in own document. duplicate calendar data user interaction fast because log in can see calendar can fetch in 1 request.

          {userid : 'x1' , cal = [{} , {}]} 

only catch here when update calendar have find document having calendar , update it. read fast in pattern write little slow.

using proper index make faster find document having specific call

       db.collection.update({cal.id : 123},{}); 

Comments