Alexandru Gorgos
Alexandru Gorgos

Reputation: 35

Uncaught TypeError: strapi.query is not a function

I'm trying to get the value of a field from a single type collection in the home page of a strapi plugin.

const test = strapi.query('global-settings').find({},{'externalUrl':1})

It's returning me an Uncaught TypeError: strapi.query is not a function Any idea why?

Upvotes: 0

Views: 2521

Answers (2)

Query engine doesn’t have a find method, only findOne and findMany.

interface QueryFromContentType<T extends keyof AllTypes> {
  findOne(params: FindParams<AllTypes[T]>): Promise<any>;
  findMany(params: FindParams<AllTypes[T]>): Promise<any[]>;
  findWithCount(params: FindParams<AllTypes[T]>): Promise<[any[], number]>;
  findPage(params: FindParams<AllTypes[T]>): Promise<{ results: any[]; pagination: Pagination }>;

  create(params: CreateParams<AllTypes[T]>): Promise<any>;
  createMany(params: CreateManyParams<AllTypes[T]>): Promise<{ count: number }>;

  update(params: any): Promise<any>;
  updateMany(params: any): Promise<{ count: number }>;

  delete(params: any): Promise<any>;
  deleteMany(params: any): Promise<{ count: number }>;

  count(params: any): Promise<number>;

  attachRelations(id: ID, data: any): Promise<any>;
  updateRelations(id: ID, data: any): Promise<any>;
  deleteRelations(id: ID): Promise<any>;

  populate<S extends AllTypes[T]>(entity: S, populate: PopulateParams): Promise<S>;

  load<S extends AllTypes[T], K extends keyof S>(
    entity: S,
    field: K,
    populate: PopulateParams
  ): Promise<S[K]>;
}

Upvotes: 0

Pablo Palacios
Pablo Palacios

Reputation: 2947

I am not sure about the last part of your request. But remember that those requests are asynchronous, so try adding await to the call.

This is an example of a query I am using.

const user_settings = await strapi.query('user-settings').find({Send_Monthly_Email: true})

So, that's why I don't understand why you have an empty parameter on that query. >> find({},{'externalUrl':1})

I am assuming you are inside a controller or inside a service.

Upvotes: 1

Related Questions