My approach differs from the one already presented.
I keep my queries in the native mongosh/JS format inside a file. At run time, outside mongosh, in Java in particular, I read the file and get back a org.bson.Document. See Java query from shell script - #2 by steevej for more details.
I am pretty sure BsonDocument has a parse method to do the same.