Nested Mongo collection: Find and update only parts

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!

To query only the topic element which matched query condition: read this document https://docs.mongodb.com/manual/reference/operator/projection/positional/
To update only matched element: read this document https://docs.mongodb.com/manual/reference/operator/update/positional/

Thank you for your answer.
I tried to play around a little with that operator by using the insecure package and use the js console, however it seems like Minimongo does not support this operator?
That’d be unfortunate - I needed it in a Method I was writing that was supposed to be shared between client and server, in order to do the necessary data retrieval and updating on the server & instantly make the former available on the client as well without having to wait for a subscription update.

Yes, Minimongo has some limitations.
The subscription will update in milliseconds, almost instantly.
You can also define one method but has different behaviors on server and client to solve that minimongo issue.