您的位置:首页 > 数据库 > Mongodb

mongoDB命令

2015-06-25 19:18 716 查看
删除数据库后(不知道是不是要每个moongod都删除liu)

进入admin  不用新建数据库liu

直接db.runCommand( { enablesharding : “liu” } );

db.runCommand( { shardcollection :“liu.docs”,key:{"name":"hashed"} } );

 

 

db.runCommand( { enablesharding :“<dbname>” } );

db.runCommand( { shardcollection :“<namespace>”,key : <shardkeypatternobject> });

 

db.c2.drop()

db.createCollection('c2')

db.c2.ensureIndex({LOG_DATE:"hashed"})

sh.shardCollection("mydb.c2",{"LOG_DATE": "hashed"})

 

chunksize:

use config

db.settings.find()

db.settings.save( { _id:"chunksize",value: <sizeInMB> } )

 

sh.enableSharding("<database>")

 

sh.getBalancerState()

sh.stopBalancer()

sh.startBalancer()

 

mongostat -h 192.168.137.104:30000

 

      MongoDatabase database = server.GetDatabase("admin");

           CommandDocument cd = new CommandDocument

           {

               {"listshards","1"}

           };

        CommandResult cr=database.RunCommand(cd);

        Console.WriteLine(cr.Response);

 

           MongoDatabase database1 = server.GetDatabase("liu");

           database1.CreateCollection("docs");

           MongoCollection collection =database1.GetCollection<Entity>("docs");

           var keys = new IndexKeysBuilder();

           keys.Hashed("name");

           collection.CreateIndex(keys);

 

1.Determine what you will use for the shardkey. Your selection of the shard key affects the efficiency of sharding.

See the selection considerations listed inthe Considerations for Selecting Shard Key.

2.If the collection already contains datayou must create an index on the shard key using ensureIndex().

If the collection is empty then MongoDBwill create the index as part of the sh.shardCollection() step.

3.Enable sharding for a collection byissuing the sh.shardCollection() method in the mongo shell. The method uses thefollowing syntax:

sh.shardCollection("<database>.<collection>",shard-key-pattern)

 

Mongos 锁的问题 ,需要时间处理

This is not really an error message: it'smore of an informational

message. It indicates that a 'mongos' process attempted to start a

balancing round while one was already inprogress.  This is a normal part

of sharded operation, and this message can besafely ignored.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mongodb 数据库 database