Take the 2-minute tour ×
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. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.