运行mongo命令

举例:想要给某个集合重建索引

  • pymongo代码中

    import pymongo
    
    MongoDbName = "shortLink"
    MongoUri = 'mongodb://127.0.0.1:27017/%s' % MongoDbName
    
    mongoClient = pymongo.MongoClient(MongoUri)
    mongoDb = mongoClient[MongoDbName]
    
    mongoDb.command({"reIndex":"gameShortLink"})
    
  • mongo shell
    use shortLink
    db.command({ reIndex: "gameShortLink" })
    

官网文档:

collection – Collection level operations — PyMongo 3.12.0 documentation

reIndex — MongoDB Manual

results matching ""

    No results matching ""