BogdanB
Convex Community3y ago
2 replies
Bogdan

Can i check equality like this?

the docs say to use combining operators if you want to for example return all documents where the name is either "Alex" or "Emma"
// Get all users named "Alex" or "Emma".
const usersNamedAlexOrEmma = await ctx.db
  .query("users")
  .filter((q) =>
    q.or(q.eq(q.field("name"), "Alex"), q.eq(q.field("name"), "Emma"))
  )
  .collect();


but i found that you could also do

const usersNamedAlexOrEmma = await ctx.db
  .query("users")
  .filter((q) =>
    q.eq(q.field("name"), "Alex" || "Emma")
  )
  .collect();


is there a reason i should not use the ladder? it reads much better imo.
Was this page helpful?