-
Notifications
You must be signed in to change notification settings - Fork 90
Bad types for MangoSelector interface #428
Description
Please read these guidelines before opening an issue.
Bug Description
Bad types for MangoSelector interface. Unable to write proper interface which is allowed by CouchDB and MongoDb references.
http://docs.couchdb.org/en/latest/api/database/find.html#selector-syntax
https://docs.mongodb.com/manual/reference/operator/query/
1. Steps to reproduce and the simplest code sample possible to demonstrate the issue
Once you have your instance for cloudant and then point to the database, in this example we are using a database called 'reservations', when we use the method 'find' it receives and object and one of those properties is selector, which receives the mangoquery to execute, there is where we cannot use reserved words from mango like $and, $eq, $lte, it throws an error when specifying them:
2. What you expected to happen
User should be able to use those operators without receiving an error message from them. I found that this is issue was reported and corrected directly on the Nano library, this is the reported issue:
apache/couchdb-nano#202
So if Im not wrong it would be just a matter of updating the Nano dependency on the Cloudant project in order to resolved it, right now Im applying the changes described on that issue manually in order to let me run the queries and it works.
On the nano.d.ts file we need to change the declaration of the MangoSelector interface for this:
Old code:
interface MangoSelector {
[key: string]: MangoSelector | MangoValue | MangoValue[];
}
New code:
type MangoOperator = '$regex' | '$eq' | '$gt' | '$gte' | '$lt' | '$lte' | '$ne' | '$and' | '$or' | '$not' | '$nor' | '$all' | '$elemMatch' | '$allMatch' | '$in'
interface MangoSelector {
[K in MangoOperator | string]: MangoSelector | MangoValue | MangoValue[];
}
3. What actually happened
User receives the next error message when using the operators:
Environment details
- Node.js version
12.18.2
- @cloudant/cloudant version
4.2.4