Filtering and search by ID does not work
See original GitHub issueDescribe the bug Filtering and search by ID does not work. As far as I understand, @admin-bro/mongoose has wrong cast of type ObjectId. There is no id in property types and @admin-bro/mongoose converts ObjectId to string. As a result, a regular expression string filter is obtained
Error
[Node] 2021-01-14 19:38:43 error: Error: Can't use $options [Node] at ObjectId.SchemaType.castForQuery (/home/doss/Projects/fitnes-batut/node_modules/mongoose/lib/schematype.js:1495:13) [Node] at ObjectId.SchemaType.castForQueryWrapper (/home/doss/Projects/fitnes-batut/node_modules/mongoose/lib/schematype.js:1467:22) [Node] at cast (/home/doss/Projects/fitnes-batut/node_modules/mongoose/lib/cast.js:310:39) [Node] at model.Query.Query.cast (/home/doss/Projects/fitnes-batut/node_modules/mongoose/lib/query.js:4786:12) [Node] at model.Query.Query._castConditions (/home/doss/Projects/fitnes-batut/node_modules/mongoose/lib/query.js:1874:10) [Node] at model.Query.<anonymous> (/home/doss/Projects/fitnes-batut/node_modules/mongoose/lib/query.js:1901:8) [Node] at model.Query._wrappedThunk [as _find] (/home/doss/Projects/fitnes-batut/node_modules/mongoose/lib/helpers/query/wrapThunk.js:16:8) [Node] at /home/doss/Projects/fitnes-batut/node_modules/kareem/index.js:369:33 [Node] at processTicksAndRejections (internal/process/task_queues.js:79:11)
Installed libraries and their versions
- admin-bro@3.3.1
- admin-bro-expressjs@3.0.1
- @admin-bro/mongoose@1.1.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:8
- Comments:7
@Gadana1 's solution involves copy-pasting code out of the
adminjs
codebase, which is pretty fragile. At any rate, I did more digging and the issue is actually with@adminjs/mongoose
. Somebody actually raised a PR to fix this in December, which has been approved but not merged: https://github.com/SoftwareBrothers/adminjs-mongoose/pull/39Any chance we can get that merged and released?
The only way I could solve this was to ad a global
list
action. So if_id
is passed then I get the item by id else, proceed with the normal flow.// global.js
// index.js -> [Your Initializing script]