Guest User

Untitled

a guest
Jun 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. # Query to get iOS 9 total users and iOS9 active users
  2. User.collection.aggregate([{'$unwind' => '$care_provider_ids'}, {'$unwind' => '$provider_information'}, {'$project' => {'match_cpid' => {'$eq' => ['$care_provider_ids', '$provider_information.care_provider_id']}, 'ios_version_number' => 1, 'provider_information' => 1}}, {'$match' => {'$and' => [{'ios_version_number' => /iOS 9.*/}, {'provider_information.active' => true}, {'match_cpid' => true}]}}, { '$group' => { _id: '$provider_information.care_provider_id', ios9_count: { '$sum' => 1 }}}, {'$sort' => { '_id' => 1}}]).each {|row| cp = CareProvider.where(_id: row[:_id]).first; puts "#{cp._id};#{cp.name};#{UsersQuery.in(cp).count};#{UsersQuery.in(cp).where({'ios_version_number' => /iOS 9.*/}).count};#{row[:ios9_count]};" if cp}
  3.  
  4. # Query to get total active users
  5. User.collection.aggregate([{'$unwind' => '$care_provider_ids'}, {'$unwind' => '$provider_information'}, {'$project' => {'match_cpid' => {'$eq' => ['$care_provider_ids', '$provider_information.care_provider_id']}, 'provider_information' => 1}}, {'$match' => {'$and' => [{'provider_information.active' => true}, {'match_cpid' => true}]}}, { '$group' => { _id: '$provider_information.care_provider_id', active_users: { '$sum' => 1 }}}, {'$sort' => { '_id' => 1}}]).each {|row| cp = CareProvider.where(_id: row[:_id]).first; puts "#{cp._id};#{cp.name};#{UsersQuery.in(cp).count};#{row[:active_users]};" if cp}
Add Comment
Please, Sign In to add comment