zoukankan      html  css  js  c++  java
  • 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"
    });
  • 相关阅读:
    Leetcode 191.位1的个数 By Python
    反向传播的推导
    Leetcode 268.缺失数字 By Python
    Leetcode 326.3的幂 By Python
    Leetcode 28.实现strStr() By Python
    Leetcode 7.反转整数 By Python
    Leetcode 125.验证回文串 By Python
    Leetcode 1.两数之和 By Python
    Hdoj 1008.Elevator 题解
    TZOJ 车辆拥挤相互往里走
  • 原文地址:https://www.cnblogs.com/Mint-diary/p/14516281.html
Copyright © 2011-2022 走看看