美文网首页
2019-11-27 Mongodb使用

2019-11-27 Mongodb使用

作者: 你呀呀呀 | 来源:发表于2019-11-27 15:18 被阅读0次

    update

    • 更新数组
      • $push
      • $addToSet 可以去重
        • $each 循环添加到数组
    • $set 设置值
    • $max 取最大
    • $min 取最小
    • $setOnInsert 当查询条件没有查到时,将额外的信息就添加到文档中。
    db[table].update_one({
        'domain': domain}, {
        '$addToSet': {
            "tag": data['tag'],
            "url": data["url"],
            'sub_domain': {"$each": data['subdomain']},
            'mail_server': {"$each": data['mailserver']},
            "find_detail": {"source": data['source'],
                            "collection_time": data['collect_time'],
                            "first_time": data['first_time'],
                            "tag": data['tag'],
                            'url': data['url'],
                            'ip': data['ip']}
        },
        '$set': {
            "ip": data['ip']
        },
        '$max': {
            "last_time": data['last_time']
        },
        '$min': {
            "first_time": data['first_time'],
            "first_collect_time": data['collect_time']
        },
    
        '$setOnInsert': {
            "whois": data['whois']
        }
    }, upsert=True)
    

    上面就是我使用到的方法


    时间
    是使用utc时间存储,也就是跟本地时间差8个小时

    相关文章

      网友评论

          本文标题:2019-11-27 Mongodb使用

          本文链接:https://www.haomeiwen.com/subject/cnrpwctx.html