0

I am building an app for sharing summaries between students that behaves like a social network.

A signed user will be able to upload summaries and access a feed of uploaded summaries.

The way I have it right now:

user schema:

var userSchema = mongoose.Schema({
    username : String,
    password : String,
    summeries: [mongoose.Schema.Types.ObjectId]
  });

summaries schema:

var summerySchema = mongoose.Schema({
    title : String,
    username : String,
    date: Date
});

I want to change it so that summerySchema is embedded to userSchema like this:

var userSchema = mongoose.Schema({
    username : String,
    password : String,
    summeries: [summerySchema]
  });

but if do so, how do I query the (let's say) 10 newest summaries from all users? (without going through the entire database? in fear of very long wait time and server overload).

xyzWty
  • 133
  • 1
  • 14
Eyal Harush
  • 69
  • 2
  • 2
  • 8
  • 1
    Possible duplicate of [MongoDB relationships: embed or reference?](https://stackoverflow.com/questions/5373198/mongodb-relationships-embed-or-reference) – Ashh Nov 26 '18 at 16:19
  • 3
    Possible duplicate of [MongoDB Many-to-Many Association](https://stackoverflow.com/questions/2336700/mongodb-many-to-many-association) –  Nov 26 '18 at 16:20
  • thank you for your comments. I edited the post according to these posts with an updated question. – Eyal Harush Nov 26 '18 at 17:06

0 Answers0