. , :
, , , .
, , PATCH push, , . dict ({"slot": {"thing1": "data1", "thingX": "dataX"}}), :
'mycollection': {
'type': 'list',
'schema': {
'type': 'dict',
'schema': {
'thing1': {'type': 'string'},
'thingX': {'type': 'string'},
}
}
}
, (list type expected). , :
from eve.data.mongo.validation import Validator
from flask import request
class MyValidator(Validator):
def validate_replace(self, document, _id, original_document=None):
if self.resource = 'mycollection' and request.method = 'PATCH':
return True
return super(Validator, self).validate(document)
, , .
PATCH. . , - ($set) . , , , . , , .
, $push $set, mycollection PATCH. - :
from eve.io.mongo import Mongo
from flask import request
class MyMongo(Mongo):
def update(self, resource, id_, updates, original):
op = '$push' if resource == 'mycollection' else '$set'
return self._change_request(resource, id_, {op: updates}, original)
:
app = Eve(validator=MyValidator, data=MyMongo)
app.run()
; , , , .
push- Mongo. / , MONGO_UPDATE_OPERATOR/MONGO_UPDATE_OPERATOR, . $set, API . , - , , $push. , , , , , Eve 0.6 .
, .