D
D
d22072020-05-25 19:52:43
MongoDB
d2207, 2020-05-25 19:52:43

How to get data from MongoDB?

Hello.
I want to take data from the front from the database. I get a pending promise. But I don't know where he is. The .find() method returns a special object, not a promise. Or should I wrap it in a promise and call resolve? To be honest, it seems to me that at the front it is done differently and I stupidly messed something up.

let mongoose = require('mongoose');
    mongoose.connect(
      'mongodb+srv://d2207:[email protected]/test?retryWrites=true&w=majority',
      {useNewUrlParser: true, useUnifiedTopology: true}
    );
    
    let db = mongoose.connection;
    db.on('error', console.error.bind(console, 'connection error:'));
    db.once('open', function() {
      console.log("mongodb are connected")
    });
    
    let products = db.collection('TestProductCollection2').find();
    console.log(products);
    db.close();

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question