• mongo 分片


    # -*- coding: utf-8 -*-
    from pymongo import MongoClient
    
    mongodb_uri = "mongodb://user:password@127.0.0.1:27017/?authSource=admin"
    
    client = MongoClient(mongodb_uri)
    
    for db_name in [
        "paper"
    ]:
        db = client[db_name]
        paper_name_list = list(paper_db.list_collection_names())
        paper_name_list.sort()
        for paper_name in paper_name_list:
            print(paper_name)
            col = db[paper_name]
            index_info = col.index_information()
            client.admin.command("shardCollection", f"{db.name}.{paper_name}", key={"_id": 1})
    db.createCollection("bioone");
    
    db.getCollection("bioone").createIndex({
        Year: NumberInt("1")
    }, {
        name: "Year_1"
    });
    db.createCollection("paper");
    
    db.getCollection("paper").createIndex({
        "author.id": NumberInt("1")
    }, {
        name: "author_id_index"
    });
    
    db.getCollection("paper").createIndex({
        "affiliation.id": NumberInt("1")
    }, {
        name: "affiliation_id_index"
    });
    
    db.getCollection("paper").createIndex({
        "first_author.id": NumberInt("1")
    }, {
        name: "first_author_id_index",
        partialFilterExpression: {
            "first_author.id": {
                $gt: NumberInt("0")
            }
        }
    });
    
    db.getCollection("paper").createIndex({
        "first_affiliation.id": NumberInt("1")
    }, {
        name: "first_affiliation_id_index",
        partialFilterExpression: {
            "first_affiliation.id": {
                $gt: NumberInt("0")
            }
        }
    });
    
    db.getCollection("paper").createIndex({
        "reference_list": NumberInt("1")
    }, {
        name: "reference_index"
    });
    
    db.getCollection("paper").createIndex({
        "venue.id": NumberInt("1")
    }, {
        name: "venue_id_index",
        partialFilterExpression: {
            "venue.id": {
                $gt: NumberInt("0")
            }
        }
    });
    
    db.getCollection("paper").createIndex({
        "journal.id": NumberInt("1")
    }, {
        name: "journal_id_index",
        partialFilterExpression: {
            "journal.id": {
                $gt: NumberInt("0")
            }
        }
    });
    
    db.getCollection("paper").createIndex({
        "conference_series.id": NumberInt("1")
    }, {
        name: "conference_series_id_index",
        partialFilterExpression: {
            "conference_series.id": {
                $gt: NumberInt("0")
            }
        }
    });
    
    db.getCollection("paper").createIndex({
        "conference_instance.id": NumberInt("1")
    }, {
        name: "conference_instance_id_index",
        partialFilterExpression: {
            "conference_instance.id": {
                $gt: NumberInt("0")
            }
        }
    });
    
    db.getCollection("paper").createIndex({
        "field.id": NumberInt("1"),
        "analysis.citation_count": NumberInt("1")
    }, {
        name: "field_id_index"
    });
  • 相关阅读:
    安装Linux应用软件的五种基本方法
    gprof使用介绍
    Linux内核对象模型(subsystem,kset,kobject)
    kernel 目录 解析
    linux板级设备的初始化过程(转)
    Linux下I2C驱动程序的分析
    I2C总线设备驱动解析
    linux proc文件系统学习 (转)
    cscope的用法
    mvc3 Razor PartialView视图中Html.DropDownList用法
  • 原文地址:https://www.cnblogs.com/Mint-diary/p/14516281.html
Copyright © 2020-2023  润新知