// it happens when you pass an invalid id to mongoose.
// so first check it before proceeding, using mongoose isValid function
import mongoose from "mongoose";
// add this inside your route
if( !mongoose.Types.ObjectId.isValid(id) ) return false;
// my problem is caused by path "/:params"
router.get("/:params", async (req, res) => {})
// can solve it as follows
router.get("/add-some-path/:params", async (req, res) => {})
// or
router.get("/:params/add-some-path", async (req, res) => {})
import mongoose from "mongoose";
// add this inside your route
if( !mongoose.Types.ObjectId.isValid(id) ) return false;
//Maybe try with .Array in your schema
Bilhete: { type: Schema.Types.Array, ref: "Bilhete" },