Will.S89
Will.S89

Reputation: 327

Error: not connected to mongos

I am attempting to create and populate a series of shards with mongo. However I keep getting the error below:

enter image description here

Error:not connected to mongos.

I have 'mongod' running in the background. Is this different to mongod? I have tried to run 'mongos' in the cmd line but this also gives me an error.

How do I get rid of this error?

Thank you

enter image description here

Upvotes: 0

Views: 6618

Answers (1)

justcompile
justcompile

Reputation: 3542

It would appear as though your cluster doesn't have all of the components required to function, so you will indeed need to have (amongst other things) at least 1 mongos instance running.

I would imagine (as there is no detail on the error you received when starting mongos) the reason you couldn't run the mongos daemon was because it's configured to run on the same port as mongod. So if you're attempting to run all the of the components on 1 machine, you will need to set different port numbers for each component.

mongod is the daemon which runs a MongoDB instance (the data store), and mongos is the router service for your cluster.

You will need:

  • a number of mongod instances running as your shards (where the data is actually sorted)
  • 3 mongod instances running as config servers (meta data of which shard contains which range of data (based on your shard keys)
  • 1 or more mongos instances which are your routers - decides (based on information from the config servers) which shard(s) it needs to query & then handles sorting & merging of the results before returning the query results. Also, your mongos servers are the endpoints you actually connect to from your client.

When you have all of the components running, you will then need to connect to one of your mongos instances in order to initialise the shard, manage & query the data behind it.

In a standalone or replica-set configuration, you connect to one of the mongod instances in order to query it, manage it etc. In a Sharded cluster, you connect to one of the mongos instead which manages the routing of your queries.

This tutorial is pretty good & helped me a bunch when I was first playing with Sharded clusters

https://docs.mongodb.com/manual/tutorial/deploy-shard-cluster/

Upvotes: 2

Related Questions