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

145
Views
Cómo obtener datos de mongodb en la página web real usando node js, reactjs, express

Estos son mis datos que se obtienen después de ejecutar la consulta en el terminal mongo 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 },

Por favor sugiera

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esto se puede hacer usando mangosta. Mongoose es una herramienta de modelado de objetos MongoDB diseñada para trabajar en un entorno asíncrono. Consulte: https://www.npmjs.com/package/mongoose para obtener más información y ejemplos.

Pasos:

Incluye mangosta:

 var mongoose = require('mongoose');

Conectarse a la base de datos:

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

Definir esquema:

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

});

Definir modelo:

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

Extraer datos y volver a la página web de guardia:

 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); } }); });

En su página web, puede usar una solicitud de obtención de AJAX para obtener sus datos y luego manipularlos.

 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();

Espero que esto ayude

about 4 years ago · Santiago Trujillo 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!