Closed coderinblack08 closed 4 years ago
Have you tried converting the id to an object ID?
yes, that is what the hook is supposed to do :)
Sorry. I missed the hook on my first read.
I recommend setting a debugger or breakpoint in the remove
method of feathers-mongodb
and see what's actually making it into the adapter.
I'm not quite familiar with the vscode debugging tool, may you elaborate or provide a working example if possible? That would be awesome.
It seems that the error says id, not _id? Is this a problem?
import { NullableId, Params } from '@feathersjs/feathers';
import { Service, MongooseServiceOptions } from 'feathers-mongoose';
import { model } from 'mongoose';
import { Application } from '../../declarations';
export class Stars extends Service {
//eslint-disable-next-line @typescript-eslint/no-unused-vars
constructor(options: Partial<MongooseServiceOptions>, app: Application) {
super(options);
}
async remove(id: NullableId, params: Params) {
const removedStar = await model('stars').deleteOne({ _id: id });
return removedStar;
}
}
I overwrote the service, it seems like a hack, is there a better way?
The better way is for it to just work, but we don't know why it's not working in your case. This override should work just fine.
Interestingly we are experiencing the same issue with NeDB. Investigations are running...
I don't think this is the case with your MongoDB driver, but I stumbled across something interesting. So this is for reference purposes only:
The package @feathers-nedb
expands the deletion request to this NeDB query:
$and: [ { undefined: 'StiJfdsHlnNtkqNX' } ]
Of course it won't find a document with this query.
EDIT: Please check if that's the case for you too by placing a console.log after this line: https://github.com/feathersjs-ecosystem/feathers-mongodb/blob/6bf168269f7cbb9f329cc8a530d5ee7677b645f7/lib/index.js#L46
Extended from issue: https://github.com/feathersjs/feathers/issues/2044
Error Message
Client Code
Backend hook
My thoughts
It seems that the query _id and the id property are different... I don't think this is the problem because the id property is the correct id and it is anything this:
Resources looked at https://docs.feathersjs.com/help/faq.html#why-should-i-use-feathers, https://github.com/feathersjs-ecosystem/feathers-mongodb#querying