I followed along to chapter 9 Mongoose- Modeling Relationships between Connected Data and lesson 6 build the movie API.
The get method works and returns an empty array because there is no document in the new collection. When I post a new JSON object like this below
Already spent days stuck on this… Thanks for any ideas. Cheers
Only the variables defined in the Joi schema will be allowed. If the post body contains any extra fields, the entire request will be dismissed.
In this case, you’re sending a nested
genre object in your post body, but in the Joi schema you’ve not defined
genre . On the other hand, you’ve defined
genreId which is not present in the post body.
You can do one of two things.
- Remove genreId and define genre in your Joi schema as follows
- [Recommended approach] Change your post body to match your Joi schema. Instead of the genre object, send the genreId as a string.
"title": "007 No Time to Die",
The option you choose depends upon your implementation of the API.
Thanks for sharing this solution! I was really confused about the same thing.