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
aplanar varios campos al completar una consulta de mangosta

Tengo el siguiente esquema en mongoose con expressjs

 const userSchema = new mongoose.Schema({ name: { type: String, required: true }, team: { type: String }, }); const dataPointSchema = new mongoose.Schema({ type: { type: String, required: true, min: 2 }, value: { type: String, required: true }, recorder: { type: String, required: true }, player: {type: Schema.Types.ObjectId, ref: 'User'}, date: { type: Date, default: Date.now } });

Cuando relleno el punto de datos con el usuario, obtengo el equipo del jugador y el _id como un objeto, y quiero aplanarlo a la siguiente estructura: Comando de población:

 Datapoint.find({}).populate([{path:'player',select:['team']}])

salida de corriente:

 { player: {_id:"_id from User",team:"team from User"}, _id: '1', type: 'shot', value: 'made', recorder: 'David', date: ' 2021-09-21T21:12:00.025Z', __v: 0, }

salida deseada

 { player: "_id from User", _id: '1', type: 'shot', value: 'made', recorder: 'David', date: ' 2021-09-21T21:12:00.025Z', __v: 0, player.team: "team from User" }

¿Alguna idea de cómo hacer esto?

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

0

 const player = { player: {_id:"_id from User",team:"team from User"}, _id: '1', type: 'shot', value: 'made', recorder: 'David', date: ' 2021-09-21T21:12:00.025Z', __v: 0, } const flatPlayer = {...player ,player: player .player._id,team: player .player.team} console.log(flatPlayer)

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!