Start a new topic
Answered

Grouping/Aggregation Query Issues - HTML5

Hi, I am having a couple issues when aggregated/grouping the results based on a field.  Please see the issues below:


1) When aggregating/grouping based on a specific field in my collection, my reduce condition (WHERE clause in sql) isn't actually working.  The way it is writing in the HTML5 guide gives me an error and the other way I tried just doesn't reduce the output.  The blue text below is the syntax from the guide that gives me an error.  I replaced the blue with the orange code and it resolves the error, but doesn't actually reduce anything.


    var userFlashDataStore = Kinvey.DataStore.collection('UserFlash'); 

    var userFlashQuery = new Kinvey.Query();

    userFlashQuery.equalTo('resultPass', false);

 

    var aggregation = Kinvey.Aggregation.count('flashcard');

    aggregation.query(userFlashQuery);   //This is the syntax from the guide but gives an error.

   aggregation.userFlashQuery;              //Doesn't give error, but this doesn't actually reduce the output by the query

 

    var stream = userFlashDataStore.group(aggregation); //The rest is working based on the guide syntax

    ....



2) Secondly, I am wondering how I can aggregate/group data based on a property in a referenced object.  For example, if I have a object with a userID and object A (embedded).  How can I group my output by a property within object A?


Thanks in advance!

James




Best Answer
James,

Please use the following code snippet to set a query for an aggregation:

 

var userFlashDataStore = Kinvey.DataStore.collection('hotels'); 
var userFlashQuery = new Kinvey.Query();
userFlashQuery.equalTo('searchable', false);
 
var aggregation = Kinvey.Aggregation.count('searchable');
aggregation.query = userFlashQuery;

 

Thanks,

Pranav

 


James,

  1. What error you are getting?
  2. Can you send me the screenshot of the error?
  3. What version of the SDK you are using?

Thanks,

Pranav

Kinvey

1.  The error is: "Uncaught TypeError: aggregation.query is not a function"

2. image


3.  I am using SDK 3.4.1


Thanks,

James

James,

I am able to reproduce this issue. I have escalated this to engineering and will get back to you once I have more information to share.

Thanks,
Pranav
Kinvey
MLIBZ-1758

 

Thank you Pranav,


Would you be able to help with my second question?


2) Secondly, I am wondering how I can aggregate/group data based on a property in a referenced object.  For example, if I have an object with a userID and object A (embedded).  How can I group my output by a property within object A?


I would like the results be: 


userID,   ObjectA.Property1,   Count


Do you know if this is possible?


Thanks,

James

Answer
James,

Please use the following code snippet to set a query for an aggregation:

 

var userFlashDataStore = Kinvey.DataStore.collection('hotels'); 
var userFlashQuery = new Kinvey.Query();
userFlashQuery.equalTo('searchable', false);
 
var aggregation = Kinvey.Aggregation.count('searchable');
aggregation.query = userFlashQuery;

 

Thanks,

Pranav

 

Login or Signup to post a comment