Sign In Register

How can we help you today?

Start a new topic
Answered

MongoDB and aggregate

Hello, 


I tested aggregate in NoSQL and pipeline works fine, however when I try the same aggregate from CC I get error:

{
 "@class": ".GameSparksErrorResponse",
 "error": {
  "message": "Function aggregate does not accept parameters (object). (297193-event-testScanPQ#40)"
 },
 "message": "Function aggregate does not accept parameters (object). (297193-event-testScanPQ#40)"
}

My aggregate has pipeline consisting of $sort, $group, $group, $project and $sort. 


In NoSQL this aggregate is tested on my runtime collection.


How can I make it work in CC?


Best regards


Best Answer

Hello Pádraig,


Thanks for answering. I resolved my issue already, I just applied what's written in reference for aggregate.  


For anyone who would like to know, if you have more then one stage in your aggregate pipeline, for example: 
s1 = 
 { $sort : { .... } }

s2 = {  $match: { .... } }
s3 = { $group: { .... } }

s4 = { $project: { .... } }

s5 =  { $sort : { .... } }


Correct way to aggregate collection is:

Spark.runtimeCollection("someCollection").aggregate( s1, [ s2, s3, s4, s5] );


Thanks


Hi Milutin,


Can you show me your aggregation code in Cloud Code?


Just for example, I just tried this simple aggregation in Cloud Code and it worked fine.


 

var coll = Spark.runtimeCollection("playerList").aggregate({$sort:{"userName": 1}})

 

Cheers,


-Pádraig

Answer

Hello Pádraig,


Thanks for answering. I resolved my issue already, I just applied what's written in reference for aggregate.  


For anyone who would like to know, if you have more then one stage in your aggregate pipeline, for example: 
s1 = 
 { $sort : { .... } }

s2 = {  $match: { .... } }
s3 = { $group: { .... } }

s4 = { $project: { .... } }

s5 =  { $sort : { .... } }


Correct way to aggregate collection is:

Spark.runtimeCollection("someCollection").aggregate( s1, [ s2, s3, s4, s5] );


Thanks

Great to hear, if you've any more questions feel free to let me know.


-Pádraig

Thank you, Milutin!
I had smashed my head trying to figure this out!
But, where you find this in GS reference? URL please?

aggregate

signature aggregate(JSON firstOp, JSON[] additionalOps)

returns JSON

https://docs.gamesparks.com/api-documentation/cloud-code-api/cloud-data/sparkmongocollectionreadwrite.html

Login to post a comment