How to get data from server query database to client?

in Meteor.startup I have query data from Postgres database, return an array now I want to use it from Client but don’t know how to get it

  const PG_HOST = 'localhost'
  const PG_PORT = '5432'
  const PG_DATABASE = 'postgres'
  const PG_USER = 'postgres'
  const PG_PASSWORD = ''
  // const DIR_PATH = f
  const pool = new pg.Pool({
      host: PG_HOST,
      port: PG_PORT,
      database: PG_DATABASE,
      user: PG_USER,
      password: PG_PASSWORD,
   function queryEvent() {
            `SELECT *
          FROM event;`
        ).then((data) => {
            return data


upppppppppppppppppppppppppppp :smiling_face_with_tear:

I don’t know why you want your query run on startup only. But if it’s then you need to store it somewhere on your server: mongodb database, memory storage…
Then on the client, you call a method (or using pub/sub, but I don’t recomend) to fetch those data.

HI, thank you, I want to get automatic data in database to do Arcgis project, automatically update data on map, data in database is added daily

Then you need some kind of cronjob to fetch the data daily. The code in startup function run once only when you start the app. In the real life, your app will stay up and running for months, even years. You don’t want that code runs only once a year, I guess.

yes but I dont know how to get data to client T.T, let me try to create new MongoCollection

Do you know How to get it?

On the server, you store those data in a collection. On the client app, you call a method to fetch them.

thank you very much, let me try

there is a problem that it will take time to load data from the database, but after loading the page, the data has not been fully loaded, how to finish loading the database into mongo, the main page will load?

What do you mean? Do you want it work like PHP? Maybe server side rendering will help.

1 Like

Hello there! I’ve done some things with PG and Meteor these past few days. I’ve made this template/boilerplate on how to use Prisma + Postgres, which may be a good solution. In summary, you will need two methods, one for querying the data and another for mutating that data. It can be seen here on this folder

1 Like

thank you very much, I want it to run on its own to get data from postgres to use for the main page to load that data