Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
¿Cómo leer datos en la colección en MongoDB?

Estoy trabajando en una aplicación de redes sociales usando Node.js y MongoDB. Tengo un problema con la lectura de los datos en la colección. Quiero conseguir todo de la colección.

Enrutador.js:

 router.get('/feed', async (req,res) => { try{ await db.client.connect() await db.feed(db.client) res.render("feed") }catch(err){ console.log(err) }finally{ db.client.close() } })

Db.js

 async function feed(client, res){ let result = await client.db('secret_db').collection('secrets') console.log(result) }

Producción:

 Collection { s: { db: Db { s: [Object] }, options: { raw: false, promoteLongs: true, promoteValues: true, promoteBuffers: false, ignoreUndefined: false, bsonRegExp: false, serializeFunctions: false, fieldsAsRaw: {}, writeConcern: [WriteConcern], readPreference: [ReadPreference] }, namespace: MongoDBNamespace { db: 'secret_db', collection: 'secrets' }, pkFactory: { createPk: [Function: createPk] }, readPreference: ReadPreference { mode: 'primary', tags: undefined, hedge: undefined, maxStalenessSeconds: undefined, minWireVersion: undefined }, bsonOptions: { raw: false, promoteLongs: true, promoteValues: true, promoteBuffers: false, ignoreUndefined: false, bsonRegExp: false, serializeFunctions: false, fieldsAsRaw: {} }, readConcern: undefined, writeConcern: WriteConcern { w: 'majority' }, slaveOk: false } }

Tenga en cuenta que no tengo ningún problema con la representación de las páginas. El problema debe resolverse dentro de la función asíncrona feed()

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe usar el método de find de la colección para obtener los datos reales de la base de datos. En tu caso prueba esto.

 let result = await client.db('secret_db').collection('secrets').find({})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!