atw.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:aboutthiswebsite 作者: a3n 项目源码 文件源码
def _upsertData(db, clct, data):
    '''Internal: Upsert json, text or binary data to db.clct.

    json and binary files need a little pre-processing by the calling
    function(s), which then call this internal function.
    '''

    try:
        res = clct.replace_one(
            {'name': data['name']},
            data,
            upsert=True) # Create it if it doesn't exist.
    except Exception as e:
        e.args += (' '.join([
            'Collection: %s;'%(clct.name),
            'data: %s;'%(str(data)),
            'type(data) should be dict: %s'%(type(data)),
            '%s collection validation rules:'%(clct.name),
            pformat(clct.options()) ]),)
        raise

    return ('%s to %s.%s, modified: %s, upserted: %d'%(
        data['name'], db.name, clct.name,
        res.modified_count,
        1 if res.upserted_id else 0
        )).strip()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号