我有像
这样的钩子函数def before_insert(docs):
for doc in docs:
if doc['field'] == 'value':
'''Do not save this document'''
app.on_insert_resource_name += before_insert
在满足条件时,如何保存本文档?除了使用abort()
。谢谢
答案 0 :(得分:1)
您可以尝试此解决方案:
def before_insert(docs):
docs = [doc for doc in docs if not doc['field'] == 'value']
答案 1 :(得分:1)
@holdenweb实际上这个值是从数据库中获得的,
for doc in docs:
res = db.collection.find_one ({"field": doc['field']})
if res:
''' do not save this doc,
i tried doc.clear() and del doc here ,but it not work.
what shoud i do?'''
感谢您的评论。