Hi everybody,
I’ve been playing around with Meteor a bit more, and am still having quite some trouble with using Mongo, or just a NoSQL db in general.
Say I have the following data I want to store:
“Categories”, “Topics” and “Ratings”, where each Category contains multiple Topics, and each Topic has a rating.
In a relational database system, I’d simply create a table for the Categories, and then a table of topics, where the latter has a field corresponding to a category Id. Querying only parts would then be simple, depending on what I want.
In a non-relational database, in this case mongo with meteor, I tried the following (I hope the way I represent the collection is clear):
[{CategoryName, some other stuff, idk, Topics: [TopicName, Rating, some other stuff, idk]}]
Let us now take the following example collection:
[
{CategoryName: "Cat1", ..., Topics: [{TopicName: "T1", rating: 9999, ...}, {TopicName: "T2", rating: 42, ....}]},
{CategoryName: "Cat2", ... , Topics: [...]},
...
]
Now let’s say I have a Category and Topic combination, and would like to know the rating (And whatever other stuff there is). I’d like to execute some kind of find query similar to the following:
.find({CategoryName: "Cat1", Topics: [{TopicName: "T1"}]}).fetch()
This, however, will return the whole “Cat1” document, including both topics I showed above.
However, I’d like it to just return the following, partial, information:
[{CategoryName: "Cat1", ..., Topics: [{TopicName: "T1", rating: 9999, ...}]}]
As you can see, the “Topic” “T2” is omitted.
Same with updates: I’d like to do something similar to
.update({CategoryName: "Cat1", Topics: [{TopicName: "T1"}]}, {$set: {Topics: [{rating: infinityyy}]}})
which would then only update the rating of Topic T1 of Category Cat1.
How would I go about achieving this? Without having to apply extra filtering after querying the data.
Thank you for your help!