Mongo operators in graphql query

Hi,
could you please explain how to use mongo operators in gql query?

query {
  event(query: {
  	data: {
    	location: {
      	city: "Oslo"
  	  }
  	}
  }) {
    name
  }
}

returns what expected:

{
  "data": {
    "event": [
      {
        "name": "Event 1"
      }
    ]
  }
}

while:

query {
  event(query: {
  	data: {
    	location: {
      	city_eq: "Oslo"
  	  }
  	}
  }) {
    name
  }
}

returns empty, and

query {
  event(query: {
  	data: {
    	location: {
      	city: {
            $eq: "Oslo" <-------- here Syntax Error
         }
  	  }
  	}
  }) {
    name
  }
}

I was expecting something like here: https://docs.mongodb.com/realm/graphql/types-and-resolvers/#queryinput

Hi, thanks for reaching out! Since graphql doesn’t support key names that start with $ , we allow any query value to be a JSON string, so for example this should work for you:

query {
  event(query: {
  	data: {
      location: {
      	city: "{ \"$eq\": \"Oslo\" }"
  	  }
  	}
  }) {
    name
  }
}
2 Likes