0

I have User schema:

{
    name: String
    ...
}

I also have Contract schema:

{
    user: { type: ObjectId, ref: 'User' }
    ...
}

Then i want to sort contracts like this:

ContractModel.find().sort({ "user.name": -1 }).exec(...);

Is it possible somehow without getting all data? Or what are alternative solutions? Thanks

karaxuna
  • 26,752
  • 13
  • 82
  • 117
  • I could nealy post this as a *"kind of"* answer. But surely this **must** be a duplicate. MongoDB is **not** relational. It **does not** do joins. If you **need** that then use a relational database and **do not** use MongoDB. Or possibly change your thinking, maybe? – Neil Lunn Mar 22 '14 at 11:46
  • @NeilLunn I asked if there were alternative solutions. How to do this without relations? – karaxuna Mar 22 '14 at 11:50
  • You do not present enough information here for an informative answer. If you want one then **please** provide more information. But the principles are simple. If you **want** to use "related" information on a **regular** basis then **embed**. But if you can embellish on your question and otherwise expect a different "answer" then go ahead. – Neil Lunn Mar 22 '14 at 11:53
  • possible duplicate of [Node - Mongoose 3.6 - Sort query with populated field](http://stackoverflow.com/questions/19428471/node-mongoose-3-6-sort-query-with-populated-field) – JohnnyHK Mar 22 '14 at 13:44

0 Answers0