5

How do I make a query to get documents where something contains in the documents array "roles"? I want to get the below document where Trainer is a element in the array.

"enabled": true,
"profilePicture": null,
"roles": [
   "Trainer",
   "Client"
 ],
SELECT * FROM u WHERE u['$type'] = 'User' AND //roles contains Trainer
David Makogon
  • 69,407
  • 21
  • 141
  • 189
Loc Dai Le
  • 1,661
  • 4
  • 35
  • 70

1 Answers1

9

Just use ARRAY_CONTAINS. Modifying the query you had:

SELECT *
FROM u
WHERE u['$type'] = 'User'
AND ARRAY_CONTAINS(u.roles, 'Trainer')

More info here.

David Makogon
  • 69,407
  • 21
  • 141
  • 189