Docker exited with code 1

Error: docker run with  Exited (1)

Cause: the CMD you run inside the docker exits with error

Solution: Check the error in docker log by these steps:

1. sudo docker ps -a

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f4c94eb133b4 dockername:latest “httpd”  55 seconds ago  Exited (1) 54 seconds ago0.0.0.0:80->80/tcp webserver

2. sudo docker logs CONTAINER_ID

Docker exited with code 1

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 error 13431 have to have sort key in projection and removing it

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 cannot run command count(): failed on : [primary shard]

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

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

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},]}});

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

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

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

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 Overflow sort stage buffered data usage exceeds internal limit