These are chat archives for getredash/redash

9th
Jul 2015
Eran Sandler
@erans
Jul 09 2015 05:22
@j0t3x what's the problem and what's the query?
this specific code regards to how to add Sort to the mongo query
j0t3x
@j0t3x
Jul 09 2015 05:24
Eran Sandler
@erans
Jul 09 2015 05:26
since Sort in mongo queries have to have a specific order we have to use a JSON array. Each field needs a name and a direction so the format looks like this:
{
    "collection" : "mycollectionname",
    "agreggate" : [    
      {
              "$group" : {
                 "_id" : "$field_name",
                 "count" : { "$sum" : 2}
             }  
      },
      {
            "$sort" : [
                {
                    "name" : "field1",
                    "direction" : -1
                },
                {
                    "name" : "field2",
                    "direction" : 1
                }
            ]
      }
    ]
}
I couldn't use a dictionary as order would not have been preserved
and I wanted as clear JSON format as possible that don't involve too much parsing of the fields
@j0t3x your query above (assuming that's the problematic one) seems to be OK. I just hope you changed the name of the Mongo Collection just for pasting the query here.
@j0t3x also, if you get an error please paste it here
j0t3x
@j0t3x
Jul 09 2015 05:39
Yeah I changed the name of the collection, and I understand now the order required in $sort(Python case). But the issue continue, every aggregation I do I get the whole collection
Simple query is working fine
Eran Sandler
@erans
Jul 09 2015 06:57
@j0t3x strange
I have multiple such aggregation queries in redash with no problem
and I get all that I need
{
    "collection" : "submissions",
    "friendlyNames" : {
        "_id" : "date"
    },    
    "aggregate" : [
          {
                "$match" : 
                      {
                          "siteId" : "tw",
                          "status" : 130
                      }
            },
            { "$project" : { "day" : { "$substr": ["$updated", 0, 10] }}},
            { "$group" : { "_id" : "$day",  "count" : { "$sum" : 1 }} },
            {
                  "$sort" : [
                      {
                          "name" : "_id",
                          "direction" : 1
                      }    
                  ]
            }
    ]
}
works without a problem
disregard the friendlynames as its just a way to change some of the problematic names
here is an example:
Eran Sandler
@erans
Jul 09 2015 07:03
@j0t3x are you sure you have the latest code and that the redash supervisor was restarted?
it might be running old code by accident
j0t3x
@j0t3x
Jul 09 2015 14:42
I did the upgrade, I saw the mongodb.py in github and it's the same I have in the server. What else can I do to help address the issue if there's one.
j0t3x
@j0t3x
Jul 09 2015 16:06
{
    "collection" : "redash",
    "agreggate" : 
      {
              "$group" : {
                 "_id" : "$recruiter_nombre",
                 "count" : { "$sum" : 2.5 }
             }    
      }      

}
from that i get the whole collection with no grouping or counting
j0t3x
@j0t3x
Jul 09 2015 16:16
btw @arikfr , whats the string to restrict the google login with domain?
how it has to be written?
seppemarotta
@seppemarotta
Jul 09 2015 22:37

hi guys , i have tried 2 different queries

This query is the correct one:

{
    "collection" : "redash",  
    "agreggate" : 
      [

             {

                "$group" : {
                   "_id" : "$recruiter_nombre",
                   "count" : { "$sum" : 2.5 }
               }    
             },
             {
                 "$sort" : [
                     {
                         "name" : "count",
                         "direction" : -1
                     }
                 ]
             }
      ]     

}

This query is the incorrect one:

{
    "collection" : "redash",
    "friendlyNames" : {
          "_id" : "kk"
      },    
    "agreggate" : 
      [

             {

                "$grodsmklfdkmldsmk├▒d├▒kup" : {
                   "_id" : "$recruifdsfdster_nombre",
                   "cofdsfdsunt" : { "$sufdsfdsm" : 2}
               }    
             },
             {
                 "$sodfsfsfdsfdsrt" : [
                     {
                         "name" : "cofdsfdsunt",
                         "directifdsfdsfdson" : -1
                     }
                 ]
             }
      ]     

}

Both of them are returning me all the data , i dont know if there is something im misunderstanding when im writing the queries in redash ,because there is no single mongo query that outputs the correct value.