Reputation: 4360
I have a Meteor collection, let's call it Pets
. Pets can have multiple owners, so I'm storing the owner ids as an array in the collection, eg.:
var pet_id = Pets.insert({'name': 'Spot', 'ownerIds': [Meteor.userId()]})
How do I find all the pets owned by a particular user?
I can find all pets where a user is the only owner easily:
Pets.find({'ownerIds':['rzfNpWfx688hkZY3X']}).fetch()
I also tried this, but it returns an empty array:
Pets.find({'ownerIds.$':'rzfNpWfx688hkZY3X'}).fetch()
Thanks!
Upvotes: 1
Views: 85
Reputation: 4360
Ah, the solution is easy - there's even an example in the Meteor docs:
Pets.find({'ownerIds':'rzfNpWfx688hkZY3X'}).fetch()
Upvotes: 2