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

87
Views
Buscar por múltiples funciones de búsqueda agregadas en MongoDB

Realmente estoy luchando con la forma de poder buscar a través de la canción y el nombre del artista . Cada uno está en sus propias colecciones y están conectados a través de una identificación. He escrito el agregado con éxito, sin embargo, el término de búsqueda solo se filtra a través del nombre de la canción. ¿Hay alguna manera de que pueda hacer esta búsqueda tanto por el nombre de la canción como por el nombre del artista? El segundo campo por el que quiero buscar es el nombre del artista en el objeto del proyecto. Como ejemplo de la nueva búsqueda que no funciona: "Bust A Move Young MC", siendo "Young MC" el nombre del artista. En el estado actual, esto simplemente devuelve 0 resultados. Cualquier ayuda sería muy apreciada.

 const searchTerm = 'Bust A Move' let filter = [] const s = new RegExp(searchTerm.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'), 'gi') filter = ['name'].map((field) => ({ [field]: s })) const agg = await Song.aggregate([ { $lookup: { from: 'artists', localField: 'artist_id', foreignField: 'artist_id', as: 'artist' } }, { $unwind: '$artist' }, { $match: { $or: filter } }, { $project: { _id: 1, name: 1, song_id: 1, spotifyImg640: 1, artist_id: '$artist.artist_id', artistName: { name: '$artist.name' } } } ]) // Song Object { song_id: 1 name: "Bust A Move", artist_id: 1 } // Artist Object { artist_id: 1, name: "Young MC" }
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!