Building a BSON filter from raw query string

Is it possible to create a collection filter from a raw query string? If so, how?

I’m using the mongocxx driver and want to use some tested queries from the mongo shell instead of building them inconveniently with the BSONCXX streambuilder. But I can not find any examples.

I tried to convert from_json() , but this throws an error

bsoncxx::from_json("{ \"val\": { $gt: 0, $lt: 9 }}");
Got parse error at "$", position 11: "SPECIAL_EXPECTED": could not parse JSON document

whereby

collection.find(bsoncxx::from_json("{ \"val\": { \"$gt\": 0, \"$lt\": 9}}"));

is leading to an unrecoverable exception and crashes the application.