'Mongoose keep getting MongoServerError: FieldPath field names may not start with '$'
I have a collection with 5 items in it. They look like this:
[
{
"brands": ["philips"],
"departments": [],
"markets": ["TR"],
"deleted": false,
"public": true,
"name": "test",
"account_id": 2,
"creator_user_id": 7,
"creator_user_name": "Murat"
}
]
To search through this collection I'm using the following query:
db.collection.find(
{
"$and": [
{
"$or": [
{
"brands": {
"$in": ["philips"]
}
},
{
"brands": []
}
]
},
{
"$or": [
{
"departments": {
"$in": ["foo","bar"]
}
},
{
"departments": []
}
]
},
{
"deleted": false
},
{
"account_id": 2
}
]
}
)
But I'm constantly having this error:
MongoServerError: FieldPath field names may not start with '$'. Consider using $getField or $setField.
I am 100% sure that there is no mistake or typo in the query. It looks like a version error, but I tried many mongoose version updates, the error persists.
I'm using mongoose 6.2.9
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
