Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

206
Visualizações
How to send an object that I read from MongoDB to node js to another js file?

How to send an object that I read from MongoDB to node js to another js file?

I want to send arr to another js file.

 MongoClient.connect(connectionURL, { useNewUrlParser: true }, (error,
 client) => {
     if (error) {
         return console.log("Can't connect to db");
}
const db = client.db(databaseName); jasonArray0 = [
    {
        opentime: 2000,
        image: "cat.jpg"
    }
];
db.collection('stam').insertMany(jasonArray0, (error, result) => {
    if (error) {
        return console.log('Could not insert')
    }
    console.log(result.ops)
})
db.collection('stam').findOne({
    _id: new mongodb.ObjectID("61ca52a727dc9d8f089d04d6")
}, (error, task) => {
    arr.push(task.image)
}) })
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you want the data on the client side, you can create an api route and send the data as json.

If you just want the data in another js file, then you can just require the db model in the file and use db find to use the result there.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda