Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
How to get data out of mongodb in actual webpage using node js, reactjs, express

This is my data which get after run query on mongo terminal db.contacts.find();

[ { _id: 59097d937386cc3a4e7b766b,
name: 'Oreo',
email: 'oreo@gmail.com',
education: 'B.tech',
address: 'West Bengal',
mobile_no: '9120507612',
__v: 0 },
{ _id: 5909814236b6663d8575fc1f,
 name: 'John',
 email: 'john@gmail.com',
 education: 'sports',
 address: 'New Delhi',
 mobile_no: '9234567788',
__v: 0 },
{ _id: 590982281eb9ab3dd5cf54b1,
name: 'Vicky',
email: 'vicky@gmail.com',
education: 'B.Tech',
address: 'Burgeon',
mobile_no: '123456789',
__v: 0 },

Kindly suggest

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

This can be done by using mongoose. Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. See: https://www.npmjs.com/package/mongoose for more information and examples.

Steps:

Include mongoose:

var mongoose = require('mongoose');

Connect to database:

mongoose.connect('mongodb://mongo:27017/yourdatabasename');

Define schema:

var contactSchema = mongoose.Schema({
_id: String, //or _id: mongoose.Schema.Types.ObjectId
name: String,
email: String,
education: String,
adress: String,
mobile_no: Number

});

Define model:

var ContactModel = mongoose.model('yourcollectionname', contactSchema); 

Extract data and return to webpage on call:

app.get('/getusers', function(req, res) {
    ConcactMOdel.find({}}, function(err, foundData) { //empty query for all data
        if(err) {
            console.log(err);
            return res.status(500).send();
        } else {
            return res.status(200).send(foundData);
        }
    });
});

On your webpage you can use a AJAX get request to fetch your data, then manipulate it.

 var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() 
{
    if (this.readyState == 4 && this.status == 200) 
    {
        var dataSet = JSON.parse(this.response);
        //manipulate/visualise the data as you wish
    }
};
xhttp.open("GET", "/getusers", true);
xhttp.send();

Hope this helps

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda