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

93
Views
Mongoose no devuelve los elementos consultados de arrray

Considere el siguiente esquema de documento:

 var WalletSchema = new Schema({ name: { type: String, required: 'Kindly enter the name of the Coin' }, . . . coins: { type: [CoinSchema] } }); var CoinSchema = new Schema({ name: { type: String, required: 'Kindly enter the name of the Coin' }, symbol: { type: String, required: 'Kindly enter the symbol of the Coin' } . . . });

Ahora considere la siguiente función:

 exports.edit_coin = function(req,res) { Wallet.findOneAndUpdate( { name: req.params.wname, "coins.symbol": req.params.symbol }, { $set: { "coins.$": req.body, last_updated: Date.now() } },{ new: true },function(err,wallet) { if (err) res.send(err); console.log(wallet); res.json(wallet); }); }

Solo quiero ver elementos de la matriz de monedas que sean iguales al símbolo dado ( req.params.symbol ).
Cuando ejecuto la función con req.params.wname = Wallet , que es una billetera en mi base de datos que tiene dos monedas, una GOC y una BTC, y req.params.symbol = BTC con algo de JSON como el cuerpo que espero solo obtengo BTC en la consola, pero lo siguiente es lo que obtengo:

 { "_id": "61d2e17ebc07b26e3f3f692a", "name": "Wallet", "balance": 1042.8, "coins": [ { "name": "Go coin", "symbol": "GOC", "amount": 4, "rate": 21.4, "_id": "61d2e21a4b112f01592613d0" }, { "name": "Bitcoin", "symbol": "BTC", "amount": 2, "rate": 50000, "_id": "61d2e77c76fd08ea50a3aff5" } ], "last_updated": "2022-01-03T12:09:32.242Z", "__v": 0 }

¿Por qué no solo obtengo bitcoin?

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!