Author: admin

  • Mongo error update does not contain _id or shard key for pattern

    Mongo DB recommends all update() operations for a sharded collection that specify the signle document update only ‘multi:false’ option (which is by default) must include the shard key in the query condition so the query will hit only a specific shard cluster. If no shard key found and ‘multi:false’, it returns this error (See http://docs.mongodb.org/manual/core/sharded-cluster-query-router/)

    In version 2.4, the error message is ‘for non-multi updates must have _id or full shard key’

  • Mongo error 16633 text search not enabled

    Error occurs when creating a ‘text’ index in Mongo to enable text search on a field, e.g., db.collection.ensureIndex( { fieldname: “text” }),  but textSearchEnabled is not enable in mongod. Try to run mongod with textSearchEnable=true

    mongod –setParameter textSearchEnabled=true

    or add textSearchEnabled=true in mongod.conf

  • Mongo can’t canonicalize query: BadValue bad sort specification

    The sort() method only accepts 1 or -1. Other values like true or false, null… will return this error “BadValue bad sort specification”.

    .sort({“field”: 1})
    .sort({“field1”: 1, “field2”: -1})

    Reference: http://docs.mongodb.org/manual/reference/method/cursor.sort/#cursor.sort

  • Mongo shell cannot use commands write mode, degrading to compatibility mode

    You are using a new mongo (>= 2.6) shell to connect a older version mongod (2.4). The new mongo shell now integrates the write concern directly into the method (insert, update) rather than with a separate getLastError command, which is not supported by older mongod. The new shell then decide to downgrade to be compatible.

    Solution: You can simply ignore this warning or try to use the correct mongo shell version.

  • Profile currently not supported via mongos

    Command db.setProfilingLevel() cannnot be used with sharded mongos.

    However we can use db.setProfilingLevel() against any shard cluster mongod if needed

  • Modify private variable using PHP ReflectionProperty

    class Foo
    {
    private $bar = ‘0’;

    public function bar()
    {
    return $this->bar;
    }
    }

    $foo = new Foo;
    $attribute = new ReflectionProperty($foo, ‘bar’);
    $attribute->setAccessible(true);
    $attribute->setValue($foo, ‘1’);
    var_dump($foo->bar());

  • Delete branch in git

    Delete local branch:

    git branch -D [branchname]

    Delete remote branch:

    git branch -rd origin/[branchname]

  • Untrack a file in git

    git update-index –assume-unchanged [file]

    To undo:

    git update-index –no-assume-unchanged [file]