FAQ
Hi,
we have a cluster containing three replica sets. There are three mongos
instances with the application doing inserts. There is one more mongos
instance which is only doing some aggregation and exporting every night.
Furthermore on this instance there is a little PHP script which creates a
new collection for the next day and enables sharding for this collection.

The script is really super simple, its just
-------------8<-------------
$connection = new MongoClient( "mongodb://somehost:someport" );
$connection->selectDB("admin")->command(array('shardcollection'=>'tracker.view_'.date('Ymd'),'key'=>array('_id'=>1)));
-------------8<-------------
wrapped by a try-catch block.

However, if I check the sharding status next morning the collection is not
sharded.

I did some tests the last few days:
- executed db.adminCommand({flushRouterConfig: 1}) on one application
mongos. The result was, the unsharded collection gets immediately sharded.
- executed db.adminCommand( {shardCollection: "tracker.view_20130222", key:
{"_id": 1}} ) on the aggregation mongos. The result here was also the
collections gets immediately sharded and it returns "{ "ok" : 0, "errmsg" :
"already sharded" }"

So to me it seems that the information collection_xyz has to be sharded
didn't made it to either the config server or the other mongos if the
command is executed via PHP.

We use mongo php driver version 1.3.4 and mongos version 2.0.4

Does anybody have some thoughts about this? Thanks in advance!

--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongodb-user@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user+unsubscribe@googlegroups.com
See also the IRC channel -- freenode.net#mongodb

---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

  • Derick Rethans at Feb 22, 2013 at 5:24 pm

    On Fri, 22 Feb 2013, Marcus wrote:

    Hi,
    we have a cluster containing three replica sets. There are three mongos
    instances with the application doing inserts. There is one more mongos
    instance which is only doing some aggregation and exporting every night.
    Furthermore on this instance there is a little PHP script which creates a
    new collection for the next day and enables sharding for this collection.

    The script is really super simple, its just
    -------------8<-------------
    $connection = new MongoClient( "mongodb://somehost:someport" );
    $connection->selectDB("admin")->command(array('shardcollection'=>'tracker.view_'.date('Ymd'),'key'=>array('_id'=>1)));
    -------------8<-------------
    wrapped by a try-catch block.

    However, if I check the sharding status next morning the collection is not
    sharded.
    You need to check the return value of ->command(). It returns the status
    of the shardcollection operation:

    $r = $connection->selectDB("admin")->command(array('shardcollection'=>'tracker.view_'.date('Ymd'),'key'=>array('_id'=>1)));
    var_dump($r);

    Your code is correct though, for me the following worked:

    $c = new MongoClient('mongodb://localhost:15000');
    $r = $c->selectDB("admin")->command(array('shardcollection'=>'test.view_'.date('Ymd'),'key'=>array('_id'=>1)));

    I just have a different port (15000) and databasename (test).

    cheers,
    Derick

    --
    {
    website: [ "http://mongodb.org", "http://derickrethans.nl" ],
    twitter: [ "@derickr", "@mongodb" ]
    }

    --
    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb

    ---
    You received this message because you are subscribed to the Google Groups "mongodb-user" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Marcus at Feb 25, 2013 at 7:42 am
    Hi Derick,

    ok I will check the return value.

    I have set up a little cluster on a virtual machine (every mongod / mongos
    is running on a different port) and the PHP script on this mongos is
    running fine. Though there is only one mongos and the sharding command and
    the test data is comming from one script / mongos.

    I dumped the result of the command getLastError and interestingly there is
    nothing about the two other shards:

    ----------------------8<----------------------
    array(5) {
    ["shards"]=>
    array(2) {
    [0]=> string(110)
    "mongo-config1.hosting.local:27019,mongo-config2.hosting.local:27019,mongo-config3.hosting.local:27019"
    [1]=> string(111)
    "shardA/shardanode1.hosting.local:27017,shardanode2.hosting.local:27017,shardanode3.hosting.local:27017"

    }
    ....
    ["n"]=> int(0)
    ["err"]=> NULL
    ["ok"]=> float(1)
    ----------------------8<----------------------

    Regards,
    Marcus


    Am Freitag, 22. Februar 2013 18:24:43 UTC+1 schrieb Derick Rethans:
    On Fri, 22 Feb 2013, Marcus wrote:

    Hi,
    we have a cluster containing three replica sets. There are three mongos
    instances with the application doing inserts. There is one more mongos
    instance which is only doing some aggregation and exporting every night.
    Furthermore on this instance there is a little PHP script which creates a
    new collection for the next day and enables sharding for this
    collection.
    The script is really super simple, its just
    -------------8<-------------
    $connection = new MongoClient( "mongodb://somehost:someport" );
    $connection->selectDB("admin")->command(array('shardcollection'=>'tracker.view_'.date('Ymd'),'key'=>array('_id'=>1)));
    -------------8<-------------
    wrapped by a try-catch block.

    However, if I check the sharding status next morning the collection is not
    sharded.
    You need to check the return value of ->command(). It returns the status
    of the shardcollection operation:

    $r =
    $connection->selectDB("admin")->command(array('shardcollection'=>'tracker.view_'.date('Ymd'),'key'=>array('_id'=>1)));

    var_dump($r);

    Your code is correct though, for me the following worked:

    $c = new MongoClient('mongodb://localhost:15000');
    $r =
    $c->selectDB("admin")->command(array('shardcollection'=>'test.view_'.date('Ymd'),'key'=>array('_id'=>1)));


    I just have a different port (15000) and databasename (test).

    cheers,
    Derick

    --
    {
    website: [ "http://mongodb.org", "http://derickrethans.nl" ],
    twitter: [ "@derickr", "@mongodb" ]
    }
    --
    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb

    ---
    You received this message because you are subscribed to the Google Groups "mongodb-user" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Derick Rethans at Feb 22, 2013 at 5:26 pm

    On Fri, 22 Feb 2013, Marcus wrote:

    Hi,
    we have a cluster containing three replica sets. There are three mongos
    instances with the application doing inserts. There is one more mongos
    instance which is only doing some aggregation and exporting every night.
    Furthermore on this instance there is a little PHP script which creates a
    new collection for the next day and enables sharding for this collection.

    The script is really super simple, its just
    -------------8<-------------
    $connection = new MongoClient( "mongodb://somehost:someport" );
    $connection->selectDB("admin")->command(array('shardcollection'=>'tracker.view_'.date('Ymd'),'key'=>array('_id'=>1)));
    -------------8<-------------
    wrapped by a try-catch block.

    However, if I check the sharding status next morning the collection is not
    sharded.
    You need to check the return value of ->command(). It returns the status
    of the shardcollection operation:

    $r = $connection->selectDB("admin")->command(array('shardcollection'=>'tracker.view_'.date('Ymd'),'key'=>array('_id'=>1)));
    var_dump($r);

    Your code is correct though, for me the following worked:

    $c = new MongoClient('mongodb://localhost:15000');
    $r = $c->selectDB("admin")->command(array('shardcollection'=>'test.view_'.date('Ymd'),'key'=>array('_id'=>1)));

    I just have a different port (15000) and databasename (test).

    cheers,
    Derick

    --
    {
    website: [ "http://mongodb.org", "http://derickrethans.nl" ],
    twitter: [ "@derickr", "@mongodb" ]
    }

    --
    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb

    ---
    You received this message because you are subscribed to the Google Groups "mongodb-user" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.
  • Derick Rethans at Feb 22, 2013 at 5:27 pm

    On Fri, 22 Feb 2013, Marcus wrote:

    Hi,
    we have a cluster containing three replica sets. There are three mongos
    instances with the application doing inserts. There is one more mongos
    instance which is only doing some aggregation and exporting every night.
    Furthermore on this instance there is a little PHP script which creates a
    new collection for the next day and enables sharding for this collection.

    The script is really super simple, its just
    -------------8<-------------
    $connection = new MongoClient( "mongodb://somehost:someport" );
    $connection->selectDB("admin")->command(array('shardcollection'=>'tracker.view_'.date('Ymd'),'key'=>array('_id'=>1)));
    -------------8<-------------
    wrapped by a try-catch block.

    However, if I check the sharding status next morning the collection is not
    sharded.
    You need to check the return value of ->command(). It returns the status
    of the shardcollection operation:

    $r = $connection->selectDB("admin")->command(array('shardcollection'=>'tracker.view_'.date('Ymd'),'key'=>array('_id'=>1)));
    var_dump($r);

    Your code is correct though, for me the following worked:

    $c = new MongoClient('mongodb://localhost:15000');
    $r = $c->selectDB("admin")->command(array('shardcollection'=>'test.view_'.date('Ymd'),'key'=>array('_id'=>1)));

    I just have a different port (15000) and databasename (test).

    cheers,
    Derick

    --
    {
    website: [ "http://mongodb.org", "http://derickrethans.nl" ],
    twitter: [ "@derickr", "@mongodb" ]
    }

    --
    --
    You received this message because you are subscribed to the Google
    Groups "mongodb-user" group.
    To post to this group, send email to mongodb-user@googlegroups.com
    To unsubscribe from this group, send email to
    mongodb-user+unsubscribe@googlegroups.com
    See also the IRC channel -- freenode.net#mongodb

    ---
    You received this message because you are subscribed to the Google Groups "mongodb-user" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupmongodb-user @
categoriesmongodb
postedFeb 22, '13 at 1:59p
activeFeb 25, '13 at 7:42a
posts5
users2
websitemongodb.org
irc#mongodb

2 users in discussion

Derick Rethans: 3 posts Marcus: 2 posts

People

Translate

site design / logo © 2022 Grokbase