in Education by
I got this query: User.collection.aggregate([ {"$project" => { "dayOfMonth" => {"$dayOfMonth" => "$created_time"}, "month" => {"$month" => "$created_time"}, "year" => {"$year" => "$created_time"}, }}, {"$group" => { "_id" => { "dayOfMonth" => "$dayOfMonth", "month" => "$month", "year" => "$year"}, "Total" => {"$sum" => 1} }}, {"$sort" => { "created_at" => -1 }} ]) My user table has username and fullname which I need, I did something like User.collection.aggregate([ {"$project" => { "dayOfMonth" => {"$dayOfMonth" => "$created_at"}, "month" => {"$month" => "$created_at"}, "year" => {"$year" => "$created_at"}, "username" => "$username" }}, {"$group" => { "_id" => { "dayOfMonth" => "$dayOfMonth", "month" => "$month", "year" => "$year"}, "Total" => {"$sum" => 1} }}, {"$sort" => { "created_at" => -1 }} ]) but it doesn't work and gives same result like above, doesn't print username, any ideas ? My goal is get username, after grouping by created at date. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
User.collection.aggregate([ {"$project" => { "dayOfMonth" => {"$dayOfMonth" => "$created_at"}, "month" => {"$month" => "$created_at"}, "year" => {"$year" => "$created_at"}, "username" => "$username" }}, {"$group" => { "_id" => { "dayOfMonth" => "$dayOfMonth", "month" => "$month", "year" => "$year"}, "Total" => {"$sum" => 1}, "username" => {"$first" => "$username"} }}, {"$sort" => { "created_at" => -1 }} ])

Related questions

0 votes
    I am making various routes with a format like below: get "address/1000broadway" get "address/300main" This ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Aug 1, 2022 in Education by JackTerrance
0 votes
    While running the server, i am getting the error incompatible library version.Already Nokogiri is installed in ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I have 2 models: class Annotation include Mongoid::Document belongs_to :event field :desc, type: String end ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 23, 2022 in Education by JackTerrance
0 votes
    Here's my RubyGems Environment: RUBYGEMS VERSION: 2.5.2 RUBY VERSION: 2.2.2 (2015-04-13 ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    When trying to start rails console I keep getting the following error Users/rigelstpierre/.rvm/rubies/ruby-1 ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    What is current state of the art for enabling OpenID login in Ruby on Rails applications? This is a ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    I know there are several plugins that do asynchronous processing. Which one is the best one and why? The ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    I asked a question earlier, and got an excellent response, but, being a newbie to Rails and still ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    In my Rails app, I want to allow the user to connect to multiple remote locations via different protocols ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    I have been trying to run the rake db:migrate command but it ain't working. I uninstalled and ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 23, 2022 in Education by JackTerrance
0 votes
    I have a Rails app that mounts 3 engines. Each engines has their own db migrations with timestamp in ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 19, 2022 in Education by JackTerrance
0 votes
    I have some rails app, a view with a field, lets say its called 'some_field' I want to fill in ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 17, 2022 in Education by JackTerrance
0 votes
    I have a user model that has many fields (let's say 30 for this example). When the user signs ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I want to know in spine how to add and remove active class for div. In the firebug I saw ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
...