In Meteor, how can I post one object from an array field?
I have the following Mongo collection:
{
id: '123456',
name: 'GameXYZ',
reviews: [
{createdBy: 'Bob', score: 5}, {createdBy: 'John', score: 8}
]
}
I would like to create a post function that only returns the overview that Bob generated:
{
reviews: [
{createdBy: 'Bob', score: 5}
]
}
I've tried this:
return myCollection.find({'reviews.createdBy': 'Bob'}, {'reviews.$': 1});
The problem is that Meteor is returning the entire document. According to their docs, "field operators like $ and $ elemMatch are not yet available on the client side." My function works on the server, so I don't know why it doesn't work. He is doing work on the Mongolian shell.
My question is, can anyone recommend a way to post just one array object to Meteor?
source to share
This is best done as an example of comments from open meteorite . Create a new collection reviews
. You can put whatever you want, but it must have the ID of what has ever been viewed. So you can post and find it withreviews.find({reviewsId: the id of the collection; in this case 123456})