0

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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]>;
}

1 Comment

solution to the original problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.