After trying to copy a patch request form the docs and running it, I keep getting a feathers error saying that BAD REQUEST 400: "Cast to ObjectId failed for value "{ name: 'Hi', completed: true }" at path "_id" for model "schools"". Can anyone help me?
Feathers vuex version: 3.10.4
code:
let data = { name: 'Hi', completed: true };
this.$store.dispatch('schools/update', [1, data, {}]);
This error come from feathers. Are you using Mongoose ?
The error might happens because the number can"t be converted to a valid ObjectId.
Yeah I am using mongoose, can you please clarify what you mean by "the number can"t be converted to a valid ObjectId."
This error even appears when I send a get request.
this.$store.dispatch('schools/get', { query: {} });
Also, I have checked the docs, they have a way of updating/patching, but how can I make it so id does it to an existing model?
import { models } from 'feathers-vuex'
const { Todo } = models.api
const todo = new Todo({ description: 'Do Something', isComplete: false })
todo.patch({ data: { isComplete: true } })
Mongoose will try to convert the id you pass to the type it should be, and the ids in mongodb are ObjectIds.
And the number 1, in your case can't be converted to an ObjectId.
So to make it works, the update action must be called with an id that is a valid ObjectId and that exist in your mongodb collection.
And the same goes for the get method, if you correctly pass the params: [id, params].
Each items in the store has those methods on it, so the update/patch will work on it.
馃檹馃檹馃檹馃檹馃檹 Thanks so much, Better read the documentation properly next time 馃槈