Invalid flag in regex option:$

Whenever i start the nodejs server the backend and the mongodb is succesfully connected but when I send an api request to my backend from the frontend this error appears and server stops automatically. I am using a simple REST api written in express and reactjs in frontend.
MongoServerError: invalid flag in regex options: $
at Connection.onMessage (C:\Users\DELL\Downloads\SocialGuruji-master\SocialGuruji-master\api\node_modules\mongoose\node_modules\mongodb\lib\cmap\connection.js:202:26)
at MessageStream. (C:\Users\DELL\Downloads\SocialGuruji-master\SocialGuruji-master\api\node_modules\mongoose\node_modules\mongodb\lib\cmap\connection.js:61:60)
at MessageStream.emit (node:events:513:28)
at processIncomingData (C:\Users\DELL\Downloads\SocialGuruji-master\SocialGuruji-master\api\node_modules\mongoose\node_modules\mongodb\lib\cmap\message_stream.js:124:16)
at MessageStream._write (C:\Users\DELL\Downloads\SocialGuruji-master\SocialGuruji-master\api\node_modules\mongoose\node_modules\mongodb\lib\cmap\message_stream.js:33:9)
at writeOrBuffer (node:internal/streams/writable:391:12)
at _write (node:internal/streams/writable:332:10)
at MessageStream.Writable.write (node:internal/streams/writable:336:10)
at TLSSocket.ondata (node:internal/streams/readable:754:22)
at TLSSocket.emit (node:events:513:28) {
ok: 0,
code: 51108,
codeName: ‘Location51108’,
‘$clusterTime’: {
clusterTime: Timestamp { low: 89, high: 1696426214, unsigned: true },
signature: {
hash: Binary {
sub_type: 0,
buffer: Buffer(20) [Uint8Array] [
118, 51, 93, 94, 131, 119,
194, 90, 29, 57, 213, 166,
236, 177, 73, 209, 211, 120,
84, 148
],
position: 20
},
keyId: Long { low: 17, high: 1684245988, unsigned: false }
}
},
operationTime: Timestamp { low: 87, high: 1696426214, unsigned: true },
[Symbol(errorLabels)]: Set(0) {}
}

Looks like your code is malforming a request to Mongo but without the code or query that’s being run not much else can be said.

Also please see the welcome posts on how to format a message, see the buttons on the editor to format code so it’s more readable.