Closed frankapimenta closed 7 years ago
You can adjust the selector config, see docs
can I set the query as an aggregate like this? db.profiles.aggregate([{'$unwind': '$posts'}, {'$match': {'posts.tags': {$in: ['post1']}}}, {'$group': {'_id': '$_id','posts': {'$push': '$posts'}}}, {$limit: 1}])
you have to call the aggregate
method outside of easy-search
thank you for the reply. is there any example in the docs?
No, as it's not part of what easy search tries to resolve
Maybe I was not able to explain well what I want to do.
I need that because I would like to search by tags of posts. Posts are stored in an array in the profiles collection.
const Profiles = new Meteor.Collection('profiles');
const Profile = Class.create({
name: 'Profile',
collection: Profiles,
fields: {
posts: {
type: [Object] // {title: '...', tags: [...], ...}
}
}
});
Applying (like in your example of email addresses) $elemMatch is going to return 1 match only even thought there are more. Applying $in will return the profile itself.
Is there a way of doing it by using easy search?
thank you for your answers so far! :)
Can you show me how you would achieve that without easy-search?
with a publication returning the aggregation I pasted here before (one can then skip, limit...whatever).
You can adjust the selector
argument by using the selector
configuration that's documented here http://matteodem.github.io/meteor-easy-search/docs/engines/. as to the aggregate call, that has to be done outside of easy-search.
I have tried to change the selector before this issue.
When I use $elemMatch it will return just 1 element (post) even though there are many other posts matching the query.
Using $in will return the profiles that have posts with those queried tags.
There is one way to do it that is to create a collection for Posts but I wanted to first squeeze this option first.
Where can I control the projection of the query?
to do something like this: http://stackoverflow.com/questions/3985214/retrieve-only-the-queried-element-in-an-object-array-in-mongodb-collection