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

153
Visualizações
An error occurred while loading the data of the collection file in MongoDB using the toArray() function

enter image description here

const express = require('express');
const app = express();
app.use(express.urlencoded({
    extended: true
}));
const MongoClient = require('mongodb').MongoClient;
app.set('view engine', 'ejs');

var db;

app.listen(8080, function () {
    console.log('listening on 8080');
});


app.get('/', function (req, response) {
    response.sendFile(__dirname + '/index.html');
});

app.get('/write', function (req, response) {
    response.sendFile(__dirname + '/write.html');
});


app.get('/list', function (req,response) {
    db.collection('post').find().toArray(function(err, results){
        console.log(results);
    });
    response.render('list.ejs');
});

i want to call my data from collection of mongodb database.

but i have a Typeerror "collection" undefined!

please help me!

enter image description here i tried googling and i want to show my data to browser!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here you have imported the module but you haven't configured the database.

const MongoClient = require('mongodb').MongoClient;
var mongoclient = new MongoClient(new Server("localhost", 27017), {native_parser: true});
var db = mongoclient.db("COLLECTION_NAME");

For more information check here https://mongodb.github.io/node-mongodb-native/api-generated/mongoclient.html

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