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" });