Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 24th, 2012  |  syntax: None  |  size: 1.79 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Creating query(join) or correct the design?
  2. // User, the profile is not complete there will be more fields
  3. var u = {
  4.     name: 'Michael', // Is not unique
  5.     email: 'mo@gmail.com', // Should be also unique
  6.     fbid: '4545454asdadsa'
  7. }
  8.  
  9. db.user.insert(u);
  10.  
  11. // User can have 0 to many posts
  12.  
  13. var p = {
  14.     title: 'Suprise',
  15.     body: 'Well done',
  16.     tags: ['first', 'post', 'english'],
  17.     author: 'mo@gmail.com',
  18.     created: new Date(),
  19.     modified: new Date()
  20. };
  21. db.post.insert(p);
  22.  
  23. var p = {
  24.     title: 'Weather in Estonia',
  25.     body: 'Always looks bad',
  26.     tags: ['bad', 'weather', 'estonia'],
  27.     author: 'mo@gmail.com',
  28.     created: new Date(),
  29.     modified: new Date()
  30. }
  31. db.post.insert(p);
  32.        
  33. var p = {
  34.     title: 'Suprise',
  35.     body: 'Well done',
  36.     tags: ['first', 'post', 'english'],
  37.     author: {
  38.         name: 'Michael', // Is not unique
  39.         email: 'mo@gmail.com', // Should be also unique
  40.         fbid: '4545454asdadsa'
  41.     },
  42.     created: new Date(),
  43.     modified: new Date()
  44. };
  45.        
  46. {
  47.   title: String,
  48.   body: String,
  49.   tags: [String],
  50.   author: {
  51.     name: String,
  52.     email: String,
  53.     fbid: String
  54.   },
  55.   created: Date,
  56.   modified: Date,
  57.   comments: [{
  58.     body: String,
  59.     created: Date,
  60.     modified: Date
  61.   }]
  62. }
  63.        
  64. {
  65.   name: String,
  66.   email: String,
  67.   fbid: String,
  68.   posts: [{
  69.     title: String,
  70.     body: String,
  71.     tags: [String],
  72.     created: Date,
  73.     modified: Date,
  74.     comments: [{
  75.       body: String,
  76.       created: Date,
  77.       modified: Date
  78.     }]
  79.   }]
  80. }
  81.        
  82. {
  83.   body: String,
  84.   created: Date,
  85.   modified: Date,
  86.   author: {
  87.     name: String,
  88.     email: String,
  89.     fbid: String
  90.   },
  91.   post: {
  92.     title: String,
  93.     body: String,
  94.     tags: [String],
  95.     created: Date,
  96.     modified: Date
  97.     comments: [{
  98.       body: String,
  99.       created: Date,
  100.       modified: Date
  101.     }]
  102.   }
  103. }