Skip to content
On this page

Filter conditions and operators

See prisma reference

equals

Value equals n.

Return all users where name equals "Eleanor":

js
const result = await app.service('User')findMany({
   where: {
      name: {
         equals: 'Eleanor',
      },
   },
})

You can also exclude the equals:

js
const result = await app.service('User')findMany({
   where: {
      name: 'Eleanor',
   },
})

not

Value does not equal n.

Return all users where name does not equal "Eleanor":

js
const result = await app.service('User')findMany({
   where: {
      name: {
         not: 'Eleanor',
      },
   },
})

in

Value n exists in list.

null values are not returned. For example, if you combine in and NOT to return user whose name is not in the list, users with null value names are not returned.

Get User records where the id can be found in the following list: [22, 91, 14, 2, 5]:

js
const getUser = await app.service('User')findMany({
  where: {
    id: { in: [22, 91, 14, 2, 5] },
  },
})

Get User records where the name can be found in the following list: ['Saqui', 'Clementine', 'Bob']:

js
const getUser = await app.service('User')findMany({
  where: {
    name: { in: ['Saqui', 'Clementine', 'Bob'] },
  },
})

Get User records where name is not present in the list (You can also use notIn):

js
const getUser = await app.service('User')findMany({
  where: {
    NOT: {
      name: { in: ['Saqui', 'Clementine', 'Bob'] },
    },
  },
})

Get a User record where at least one Post has at least one specified Category:

js
const getUser = await app.service('User')findMany({
  where: {
    // Find users where..
    posts: {
      some: {
        // ..at least one (some) posts..
        categories: {
          some: {
            // .. have at least one category ..
            name: {
              in: ['Food', 'Introductions'], // .. with a name that matches one of the following.
            },
          },
        },
      },
    },
  },
})

notIn

Value n does not exist in list.

Remark: null values are not returned.

Get User records where the id can not be found in the following list: [22, 91, 14, 2, 5]:

js
const getUser = await app.service('User')findMany({
  where: {
    id: { notIn: [22, 91, 14, 2, 5] },
  },
})

lt

Value n is less than x.

Get all Post records where likes is less than 9:

js
const getPosts = await app.service('Post')findMany({
  where: {
    likes: {
      lt: 9,
    },
  },
})

lte

Value n is less than or equal to x.

Get all Post records where likes is less or equal to 9:

js
const getPosts = await app.service('Post')findMany({
  where: {
    likes: {
      lte: 9,
    },
  },
})

gt

Value n is greater than x.

Get all Post records where likes is greater than 9:

js
const getPosts = await app.service('Post')findMany({
  where: {
    likes: {
      gt: 9,
    },
  },
})

gte

Value n is greater than or equal to x.

Get all Post records where likes is greater than or equal to 9:

js
const getPosts = await app.service('Post')findMany({
  where: {
    likes: {
      gte: 9,
    },
  },
})

Get all Post records where date_created is greater than March 19th, 2020:

js
const result = await app.service('Post')findMany({
  where: {
    date_created: {
      gte: new Date(
        '2020-03-19T14:21:00+0200'
      ) /* Includes time offset for UTC */,
    },
  },
})

contains

Value n contains x.

Count all Post records where content contains databases:

js
const result = await app.service('Post')count({
  where: {
    content: {
      contains: 'databases',
    },
  },
})

Count all Post records where content does not contain databases:

js
const result = await app.service('Post')count({
  where: {
    NOT: {
      content: {
        contains: 'databases',
      },
    },
  },
})

Use Full-Text Search to search within a String field.

Full-Text Search is currently in Preview and only available for PostgreSQL and MySQL. To use search, you'll need to enable the fullTextSearch preview feature.

prisma
generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["fullTextSearch"]
}

Find all posts with a title that contains cat or dog:

js
const result = await app.service('Post')findMany({
  where: {
    title: {
      search: 'cat | dog',
    },
  },
})

Find all posts with a title that contains cat and dog:

js
const result = await app.service('Post')findMany({
  where: {
    title: {
      search: 'cat & dog',
    },
  },
})

Find all posts with a title that doesn't contain cat:

const result = await app.service('Post')findMany({
  where: {
    title: {
      search: '!cat',
    },
  },
})

startsWith

Get all Post records where title starts with Pr (such as Prisma):

js
const result = await app.service('Post')findMany({
  where: {
    title: {
      startsWith: 'Pr',
    },
  },
})

endsWith

Get all User records where email ends with prisma.io:

js
const result = await app.service('User')findMany({
  where: {
    email: {
      endsWith: 'prisma.io',
    },
  },
})