I want to create an array of ratings, and inside this array I want somehow associate rating and date this rating was checked.
right now I have this solution:
> db.foo.find().pretty()
{
"_id" : ObjectId("511a604f546e6b3019d5e673"),
"ratings" : [
{
"rating" : 3,
"date" : ISODate("2013-02-12T15:31:27.950Z")
},
{
"rating" : 5,
"date" : ISODate("2013-02-12T15:34:12.072Z")
},
{
"rating" : 3,
"date" : ISODate("2013-02-12T15:34:33.009Z")
}
]
}
With this “schema” I see the only one BIG issue, I think it’s little to complicated to sort documents by date, if I’m wrong, please correct me. How would you design it?
Store the ratings in a separate “ratings” collection.
This strategy adds the minor complication of needing two queries to display a “foo” and its ratings (one query for each collection) but has the advantage of flexibility and scalability.
See also this advice from 10gen: Storing Comments.