RESTful Mongoose with ObjectID references RESTful Mongoose with ObjectID references mongoose mongoose

RESTful Mongoose with ObjectID references


What I usually do is:

  • I don't populate anything on a "list" request.
  • I populate all objectId references on a "show" request.

This would not make your service less RESTful, as far as I'm concerned. It will still be resource oriented and the attached data actually belongs to that specific resource. That should reduce the amount of requests you'd need to make.

Alternatively, you could create a container resource that gathers all the required information and sends it back to the client. I'd personally go with a couple of separate requests though. Especially because, since HTTP 1.1, multiple requests can be executed through the same connection. I don't think that requesting multiple JSON objects at the same time would have any significant impact on the performance of your application.

I wouldn't nest everything inside a "data" schema though.

Hope it helps and good luck!


It is, to me, more like a document-oriented data design problem than a REST design one. My approach is to drive the design of data model by the view or the pages, not to design the model first then try to fit the view to it. This somehow aligns with Reda's answer.

In order to reduce the number of requests or mongoose populations, I always allow duplications in the documents. In your example, a bucket will has an array of post id's and an array of stream ids. At the same time, a post will has an array of buckets id's and even some detailed information of each bucket. Such a design will make retrieval of the document very fast, but slow down update operations, and also introduces the risk of inconsistence.