The problem (from what I can see)
From what I can see from your output, you have a monotonically increasing shard key like ObjectId
or a Date
or something similar.
MongoDB sharding is done with key ranges over the selected shard key. Put simply, it works like "shard0000
is supposed to hold the rang from -infinity to $i
, shard0001
the keys from $h to $p
and shard0002
from $q to infinity
. With a monotonically increasing shard key, every new value will be bigger than the last one inserted, heading to infinity, so the shard which will be used is always shard0002
, instead of the writes being balanced to all shards.
So all of the write operations seem to hit shard0002
with individual chunks being migrated to the other shards. The necessary chunk migrations together with added network latency and a lot of metadata updates going on, it may well be that you have a poor write performance.
The solution
Really bad news: you can't change the shard key once it is set. You basically have to create new sharded collection with a better shard key. For choosing a proper shard key, please read Considerations for Selecting Shard Keys in the MongoDB docs.
P.S. I wasn't sure wether to answer this question, since it is slightly off topic on Stackoverflow, which is aimed at programming questions. But since usually the developers are supposed to choose the shard key, my intention was to clarify things for them. Additionally, the data modeling might be influenced by sharding considerations, so – by a small margin – I thought it was ok to answer here. However, dear reviewer, feel free to flag this answer for deletion if you think differently. I am really not sure.
Best Answer
As i have gone through your MongoDB syntax query it seems to be correct. As per your script code
demo
isdatabase
anddcoll
iscollection
and you want to restore the (.bson
) file of tweets.bson in yourdcoll
collection
.I would like to say that here before restore the (.bson) file in MongoDB. You have to make sure that your database name and collection name should be in MongoDB. If you have don't have
Collection
in database then first create thatCollection
in database.For example first connect with
mongo shell
and show the database and collection . Which you are going to restore in MOngoDB, which is exist or not.To show the database in MongoDB
For example in my environment i have checked and these databases are exist in
MongoDB
.Suppose that i want to restore (
.bson
) file in test database.Then i shall create the
collection
data in testdatabase
.Also confirm from the query , the
data
collection is intest
database or not.Here data collection is present then finally restore the (.bson) into the
data
collection
.Note: Make sure that you are restoring the (.bson) file from the
mongo shell
wheremongorestore.exe
is present. Basically this file is available in BIN folder of the MongoDB Server. In my place it isC:\Program Files\MongoDB\Server\3.6\bin
.so, the finally
mongorestore
command will be like thatI hope this will help out to you.
For further your ref mongorestore