Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a business collection.

The businesses are reviewed by users.

Each user can only review a business once. Future reviews will simply replace the former one.

This is how we store it:

 "Reviews" : {
    "gusyanto" : {
      "day" : "December 21, 2012, 8:08 am",
      "review" : "Tes review"
    "sapi" : {
      "day" : "December 21, 2012, 8:18 am",
      "review" : "makanan ini sangat enak"

Alternatively we can also use this:

 "Reviews" : [{
      "userid" : "gusyanto",
      "day" : "December 21, 2012, 8:08 am",
      "review" : "Tes review"
      "userid" : "sapi",
      "day" : "December 21, 2012, 8:18 am",
      "review" : "makanan ini sangat enak"}

So basically we want can store it as a dictionary where the key is the userid or we can store it as an array where userid is the field key. So the key in the second approach is static, namely userid.

We want to index the entries. For example, a user may want to know what businesses he has reviewed.

Which approach I should use?

share|improve this question

AFAIK, MongoDB queries are more optimized for your second approach.

with the first approach you will probably have to do a query like:

db.businesses.find({'Reviews.gusyanto': {$exists: true}})

Which is less efficient than using:

db.businesses.find({'Reviews.userid': 'gusyanto'})
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.