Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

189
Vistas
Error trying to do search for records matching criteria with MongoDB

I am taking a training course, on Udemy, and it had backend code already written, as the course is purely about frontend development. It uses a very simple MongoDB database that I created. I determined that MongoDB version 4.0.10 is installed on my computer, in case that's relevant. When trying to perform a query for matching records, I get the following error:

UnhandledPromiseRejectionWarning: MongoError: FieldPath field names may not start with '$'. at MessageStream.messageHandler (I:\DEV\Training\React For the Rest of Us\backend-api\node_modules\mongodb\lib\cmap\connection.js:268:20) at MessageStream.emit (events.js:315:20) at processIncomingData (I:\DEV\Training\React For the Rest of Us\backend-api\node_modules\mongodb\lib\cmap\message_stream.js:144:12) at MessageStream._write (I:\DEV\Training\React For the Rest of Us\backend-api\node_modules\mongodb\lib\cmap\message_stream.js:42:5) at writeOrBuffer (internal/streams/writable.js:358:12) at MessageStream.Writable.write (internal/streams/writable.js:303:10)
at TLSSocket.ondata (internal/streams/readable.js:719:22) at TLSSocket.emit (events.js:315:20) at addChunk (internal/streams/readable.js:309:12) at readableAddChunk (internal/streams/readable.js:284:9) (node:51960) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) After looking into the backend code, I found the following code that is being used to perform the query/search, and I did notice that there are $ symbols in various places.

Post.search = function(searchTerm) {
  return new Promise(async (resolve, reject) => {
    if (typeof(searchTerm) == "string") {
      let posts = await Post.reusablePostQuery([
        {$match: {$text: {$search: searchTerm}}},
        {$sort: {score: {$meta: "textScore"}}}
      ])
      resolve(posts)
    } else { 
      reject()
    }
  })
}

What exactly is wrong and how do I fix it?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Identical error here. Searching from react using axios in the main app-very simple(supposed to be). It's indicative that in my case when trying to search- "open search mode" from react", mongodb server crashes with mentioned error:
f:\PrgsReact\SimplePost\backend-api\node_modules\mongodb\lib\cmap\connection.js:268 callback(new MongoError(document));
MongoError: FieldPath field names may not start with '$'.
etc..
I'm tried to change npm ver of mongodb and axios inter alia. Thanks.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda