|
The following page recommends an ambiguous and harmful escaping scheme: https://docs.mongodb.com/v3.0/faq/developers/#dollar-sign-operator-escaping . People are recommending this escaping scheme based on the fact that its in your documentation, but its a terrible idea. This escaping scheme will break whenever the suggested unicode characters are actually used in the raw key.
Please either remove this harmful recommendation or update it with a proper unambiguous escaping method. Here's an example that is unambiguous and far more human-readable:
// returns an escaped mongo key
exports.escape = function(key)
{
return key.replace(/~/g, '~~')
.replace(/\./g, '~,')
.replace(/^\$/g, '~$')
}
// returns an unescaped mongo key
exports.unescape = function(escapedKey)
{
return escapedKey.replace(/^~$/g, '$')
.replace(/~,/g, '.')
.replace(/~~/g, '~')
}
|