Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tag parameter to tomatoes method #296

Open
andrew-chiz-muzychuk opened this issue Jun 17, 2017 · 8 comments
Open

Add tag parameter to tomatoes method #296

andrew-chiz-muzychuk opened this issue Jun 17, 2017 · 8 comments

Comments

@andrew-chiz-muzychuk
Copy link

I wanted to get a number of tomatoes for the specified period of time and with a specified list of tags (actually, only one tag, but I think it would be nice to be possible to filter out for multiple number of tags in one request).
It would be nice to have one more filter parameter as tag in tomatoes method.

@andrew-chiz-muzychuk
Copy link
Author

I use tomatoes for tracking hours worked for each client. I want to get number of hours (number of tomatoes/2) for each client for a specific time period. I have tags for each client.
What I do now is go through all tomatoes and count them.
What I want to do is to run a request in SoapUI with specific parameters to get a number of tomatoes.

@potomak
Copy link
Member

potomak commented Jun 18, 2017

There's a composite index on the tomatoes collection that includes both user_id and created_at. Getting a user's tomatoes that have been tagged, created in the selected period of time, should be even faster than counting them by tag, so I think we could easily add that feature in the API.

Any volunteer? cc @bugant @dalpo

See also #168.

@bugant
Copy link
Member

bugant commented Oct 25, 2018

@potomak would you do it with a map/reduce on mongodb?

@potomak
Copy link
Member

potomak commented Oct 25, 2018

@bugant I don't think you need a map/reduce, I think you can just run a query that counts records with some conditions.

@bugant
Copy link
Member

bugant commented Oct 25, 2018

Ah didn't get it should only return a count, I was thinking about a filtered list (index)

@potomak
Copy link
Member

potomak commented Oct 25, 2018

I think in either case you don't need map/reduce, but you can just run a query.

query = Tomato.where(user_id: user_id).where(:created_at.gt => created_at).where(:tags.in => tags)

Note: I'm not sure if that query will work, I didn't try it.

tomatoes_count = query.count

Reference: https://docs.mongodb.com/mongoid/6.4/tutorials/mongoid-queries/

@bugant
Copy link
Member

bugant commented Oct 25, 2018

Hmm, which kind of field is tags? Isn't it a string? If so, I'm not sure the in will work

@potomak
Copy link
Member

potomak commented Oct 25, 2018

It should be an array.

See

include Mongoid::Document::Taggable
and
base1.field :tags, type: Array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants