Cannot upgrade mongodb community version from 4.0.25 to 6.0.4

Hi Team,
When i upgrade existing mongodb 4.0.25 to 6.0.4, i get below error

This version of MongoDB is too recent to start up on the existing data files. Try MongoDB 4.2 or earlier.
is there any better way to do upgrade from 4.0.25 to 6.0.4

You can’t skip major version in MongoDB. The upgrade path would be.
4.0.25 → 4.2.x → 4.4.x → 5.0.x → 6.0.x

@tapiocaPENGUIN , Thanks for your answer.
We actually missed this path 4.0.25 → 4.2.x → 4.4.x → 5.0.x → 6.0.x.
We are running mongodb community version in kubernetes environment
What we plan to do is,

  • deploy mongo community version 6.0.4
  • take a backup of data from existing mongo version 4.0.25
  • restore it into mongo 6.0.4
  • decommission mongo 4.0.25.
    I hope this is doable, let me know otherwise

It is not a supported or tested upgrade method. The documented one is.

Some have had luck (or at least not come back to the forum) with export/import as your are planning.