Skip to content

Pymongo单实例升级分片集群无缝切换扩展

Notifications You must be signed in to change notification settings

idefa/pymongo_shard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

pymongo_shard

解决mongodb单实例升级分片集群后造成的不兼容问题,mongo单实例升级分片集群,默认自动开启,不用手动开启库表分片,默认表使用_id作为分片键。

使用示例

from pymongos import ShardMongoClient
from pymongo import UpdateOne,UpdateMany,DeleteMany

mongodbUri = 'mongodb://mongouser:1234567a@localhost:27017/'
client = ShardMongoClient(mongodbUri)
db = client.test

#insert data
db.num.insert_one({'id':1, 'name':'R9', 'des':'pretty'})
db.num.insert_one({'id':2, 'name':'BOY', 'des':'handsome'})
db.num.insert_one({'id':3, 'name':'cat', 'des':'nice'})
db.num.insert_one({'id':4, 'name':'dog', 'des':'clever'})


#update data
db.num.update_one({"name":"R9"},{"$set":{"des":"good"}})

#update many
db.num.bulk_write([UpdateMany({"name":"R9"},{"$set":{"des":"good"}})])


#delete data
db.num.delete_one({"name":"BOY"})

db.num.bulk_write([DeleteMany({"name":"R9"},{"$set":{"des":"good"}})])

About

Pymongo单实例升级分片集群无缝切换扩展

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages