$ is not allowed at the beginning of a field name, since in this position it is reserved to indicate query operators like $or, $addToSet, $, etc, and allowing it as part of field names would make the query language ambiguous. You can still store a query as a string value in a field
{
"query" : "{ 'a' : { '$lte' : 5 } }",
"sort" : "{ 'a' : 1 }"
}
or you could alter the key names so they no longer begin with $ and are valid for insertion into MongoDB
{
"query" : { "a" : { "_DS_lte" : 5 } },
"sort" : { "a" : 1 }
}
then modify the query after you retrieve it so it can be used. Naturally, you wouldn't want to allow _DS_ in key names in your documents in this example.
I don't know much about PHP, so perhaps these aren't the best way to store a query when using PHP, but they'll work.
-Will