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

118
Views
Relación de uno a pocos en mongodb

Soy nuevo en mongodb y quiero tener una relación de uno a pocos en mi base de datos. Quiero tener un esquema incrustado, pero estoy luchando para que funcione. Quiero que un usuario tenga muchas publicaciones, pero cuando intento insertar datos, solo se insertan el nombre, el correo electrónico y la contraseña y no los blogs. Estoy atascado y cualquier ayuda sería apreciada.

 import express from "express"; import mongoose from "mongoose"; import bodyParser from "body-parser"; import Cors from "cors"; const app=express(); const port= process.env.PORT || 5000; app.use(bodyParser.urlencoded({extended: true})); app.use(express.json()); app.use(Cors()); mongoose.connect('mongodb+srv://@cluster0.gmg3q.mongodb.net/NotScr?retryWrites=true&w=majority', {useNewUrlParser: true, useUnifiedTopology: true}); const userSchema=mongoose.Schema({ name: String, email: String, password: String, blog: [{ title: String, post: String }] }); const User= mongoose.model("User", userSchema); app.get("/", (req,res)=>{ res.send("Hello World!Welcome to NOTSCRAP backend"); }); app.post("/register", (req,res)=>{ const newUser = req.body; User.create(newUser, (err, data) => { if(err){ res.send(err) } else{ res.send(data); } }); }); app.post("/login", (req, res)=>{ const user_email = req.body.email; const user_password = req.body.password; User.findOne({email: user_email}, function(err, foundUser){ if(err){ console.log("Wrong Email"); res.send("Wrong Email"); } else{ if(foundUser){ if(foundUser.password === user_password){ console.log(foundUser); res.send(foundUser); } else{ console.log("Wrong Password"); res.send("Wrong Password"); } } else{ res.send("Wrong Email"); console.log("Wrong Email"); } } }); console.log(req.body); }); app.post("/userdata", (req, res) =>{ console.log(req.body); const id=req.body.username; User.findOne({_id: id}, function(err, foundUser){ if(err){ console.log(err) } else{ console.log(foundUser); res.send(foundUser); } }); }); app.listen(port, ()=>{ console.log(`Server is up and running on port ${port}`); })

about 4 years ago · Juan Pablo Isaza
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!