1

I have the collection "students" with following documents:

{
   "name": "A",
   "isAlumni": false,
   "info": {
       "number": 123456789,
       "bloodGroup": "O+"
   }
},
{
   "name": "B",
   "isAlumni": false,
   "info": {
       "number": 123456789,
       "bloodGroup": "B+"
   }
},
.
.
.

I am trying to write a redash query that displays students with either name A or B, isAlumni : false, and bloodGroup should be an existing field.

mongoShell query that works:

db.getCollection("students").find({"name": {$in: ["A", "B"]}, "isAlumni": false, "info.bloodGroup": {$exists: true}})

I tried writing it as redash json query:-

{
   "collection": "students",
   "query" : {
       "name": {"$in": ["A", "B"]},
       "isAlumni": false,
       "info.bloodGroup": {"$exists": true}
   }
}

Shows up as an invalid JSON. enter image description here

I did go through the MongoDB redash doc, but it wasn't as helpful.

Any help is appreciated.

  • Can you please post the screenshot of the error? Maybe there is any typo? – Valijon Dec 26 '21 at 09:34
  • @Valijon i have added the image now – MorbidScroll Dec 26 '21 at 10:41
  • 1
    Thanks. Make sure your json query don't have any extra comma. Try to change false -> False, true -> True (since it written in python and the reason of wrong json). And the last, try to change your query to [aggregation](https://redash.io/help/data-sources/querying/mongodb#Aggregation) – Valijon Dec 26 '21 at 11:02
  • @Valijon I am trying aggregate query, but are you sure about sentence casing the booleans? even in their doc they have used lower case – MorbidScroll Dec 26 '21 at 16:07
  • @Valijon can you maybe post it as a solution so I can accept it as correct. worked for me. comma issue. thank you – MorbidScroll Dec 26 '21 at 16:35
  • You may post an answer with screenshot of extra comma and help other people. Glad to help. – Valijon Dec 26 '21 at 16:43

0 Answers0