Category: errors

  • Ruby on Rails Notice: The native BSON extension was not loaded.

    Error: When using mongo gem in RoR:

    Notice: The native BSON extension was not loaded. For optimal performance, use of the BSON extension is recommended. To enable the extension make sure ENV[‘BSON_EXT_DISABLED’] is not set and run the following command: gem install bson_ext

    Cause:

    bson_ext and mongo gem are not in the same version.

    Solution: Install bson_ext and mongo gems using the same version, example: 1.9.2:

    gem install mongo -v=1.9.2
    gem install bson_ext -v=1.9.2
  • Mongo error 13431 have to have sort key in projection and removing it

    Error: When using shard collection and querying, if we explicitly want to omit a field but want to sort on that field, Mongo raises error code 13431 since mongos can’t sort without that missing field:

    db.collection.find({},{_id:0}).sort({_id:1});

    error: {
    “$err” : “have to have sort key in projection and removing it”,
    “code” : 13431
    }

    Solution: do not omit the field used in sort

  • Mongo cannot run command count(): failed on : [primary shard]

    Error: When using MongoDB sharded cluster 2.6 and php mongo driver,  db.collection.count() contains an $in operator would raise a BadValue error if using assoc array or bad numerical indexed array:

    array(‘apple’->’iphone’, ‘nokia’->’winphone’)

    array(0->’a’, ‘2’->b)

    Solution:

    In PHP, use array_values($array) to get the numerical indexed array as input for $in query

  • Mongo can’t canonicalize query: BadValue $in needs an array

    Error: From MongoDB 2.6, $in need an numerical indexed array. Associative array or malformed numerical indexed array like these will raise BadValue error:

    array(‘apple’->’iphone’, ‘nokia’->’winphone’)

    array(0->’a’, ‘2’->b)

    Solution:

    In PHP, use array_values($array) to get the numerical indexed array as input for $in query

  • Meteor: Uncaught Error: Not permitted. Untrusted code may only update documents by ID when update array element using $

    Error: Not permitted. Untrusted code may only update documents by ID when update sub array using $ in Meteor

    Cause:

    Suppose we have this doc:

    {

    _id: 1;

    tags: [

    {tag: “tag1”, count: 0},

    {tag: “tag2”, count: 0},

    ]

    }

    And we want to update tag1 count by inc with 1 with a client-side script:

    db.tags.update({_id:1, “tags.tag”: “tag1”}, {$inc: {“tags.$.count”: 1}})

    Even the above update only update a single document, Meteor will not allow us to do so because it expects only _id in the update condition.

    Solution: Update the whole tags with a modified value for tag1 count:

    db.tags.update({_id:1}, {$set: {“tags”: [{tag: “tag1”, count: 1},{tag: “tag2”, count: 0},]}});

  • Unable to activate mongo-1.12.0, because bson-2.3.0 conflicts with bson (= 1.12.0)

    Error: Unable to activate mongo-1.12.0, because bson-2.3.0 conflicts with bson (= 1.12.0) when installing both ruby gem mongo and mongoid

    Cause: mongo gem requires bson 1.12.0 while mongoid version > 3.0.0 requires moped which needs bson 2.3.0

    Solution: Use mongoid < 2.8.1 if you want to use mongo, or dump mongo and switch to moped:

    gem install mongoid -v 2.8.1

  • MongoDB Overflow sort stage buffered data usage exceeds internal limit

    Error: Overflow sort stage buffered data usage of 33558657 bytes exceeds internal limit of 33554432 bytes

    Causes: MongoDB has a 32MB limit on in-memory sort

    Solutions: Find out what field is used by the sort and create index or compound index for that fields. This will avoid the in-memory sort

    db.collection.ensureIndex({“a:1, “b”:1})

  • MongoDB MMS failed to decrypt password for job when restoring using SCP

    Causes:

    MMS Application Server and Backup Daemon are installed on different machines. And these two machines do not share the gen.key file.

    Solutions:

    On the MMS Application Server, run the following:

    grep ENC_KEY /opt/mongodb/mms/conf/mms.conf

    On the Backup Daemon Server:

    grep ENC_KEY /opt/mongodb/mms-backup-daemon/conf/daemon.conf

    If the gen.key file is missing on Backup Daemon Server or gen.key are different on the two machines, copy gen.key from MMS Application Server to Backup Daemon Server and restart Backup Daemon:

    sudo service mongodb-mms-backup-daemon restart

  • MongoDB MMS Backup failed to enqueue an oplog.

    Causes: Backup DB write error due to:

    1. run out of disk space

    2. no primary/master found

    Solution: Restart backup DB hosts should solve this error.

  • 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’