def update(self, table, key, properties, upsert = False, replace = False): if table not in ['metadata', 'tokenmaps']: properties = db.flatten(properties, token_map = self.get_token_map(table, 'encode')) if replace: update = properties else: properties.pop('_id', None) update = {"$set" : properties} self.get_collection(table).update({'_id' : key}, update, upsert = upsert)
def test_db_flatten_unflatten(self): document = {"_id": "keyname1", "nested": {"item": 1}} assert db.unflatten(db.flatten(document)) == document
def test_db_flatten(self): document = {"_id": "keyname1", "nested": {"item": 1}} assert db.flatten(document) == {"_id": "keyname1", "nested|item": 1} document = {"_id": "keyname1", "notnested": "a"} assert db.flatten(document) == document
def test_db_flatten_unflatten(self): document = {'_id': 'keyname1', 'nested': {'item': 1}} assert db.unflatten(db.flatten(document)) == document
def test_db_flatten(self): document = {'_id': 'keyname1', 'nested': {'item': 1}} assert db.flatten(document) == {'_id': 'keyname1', 'nested|item': 1} document = {'_id': 'keyname1', 'notnested': 'a'} assert db.flatten(document) == document