1

I want to insert the below dictionary into MongoDB, using pymongo. However, I get the bson.errors.InvalidDocument: key 'www.utsa.edu' must not contain '.'

One of the threads suggests, "MongoDB not allowing using '.' in key", to check_keys=False. However, I think since Mongo, uses '.' to refer nested documents, I think, this is not a good method.

So my question is, how should I insert a web site or a domain name, as the primary key.

UniversityData =    {
    'www.utsa.edu': { 
        'Social Data': {   
            'Google Places':{  
                'Address': u'One UTSA Circle San Antonio, TX 78249, United States',
                'Latitude': 42.46728199999999,
                'Longitude': -83.42548599999999,
                'rating': 3.6,
                'types': [   u'education', u'university', u'students',u'college']
            }
        },
    }
}
Community
  • 1
  • 1
  • Use it as a "value" rather than a "key". The "Primary Key" is `_id` in all MongoDB documents anyway. Using "named keys" is generally a bad practice. You nearly always actually intend to use the data as a "value" in any meaningful "database" application, so just store as a "value". – Neil Lunn Apr 17 '16 at 00:44

0 Answers0