I'm trying to save a dictionary containing a special character '.' in key portion to the MongoDB. The error is presented below, which clearly states that the key must not contain a special character '.'.
>>> import pymongo
>>> client = pymongo.MongoClient('localhost')
>>> db = client['malware']
>>> test = db['test']
>>> d = {'.aaa' : '.bbb'}
>>> test.insert(d)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python2.7/site-packages/pymongo/collection.py", line 362, in insert
self.database.connection)
bson.errors.InvalidDocument: key '.aaa' must not contain '.'
But my current information contains '.' in the key portion of the data, which I need to store to MongoDB. Currently I was just deleting the '.' from the string, another options would be to replace it with '_' or some other special character.
Nevertheless, all results in loss of information, because if I have a key '.aaa' and a key 'aaa' and if I convert '.' into '' then the keys are exactly the same and I lose some information. Why isn't Mongo allowing me to save the '.aaa' into the DB?
Any ideas how to approach the problem?