Where is non-shard'd data stored

Hi,

Firstly - these courses are excellent - thank you. I’m a MySQL guy attempting to bend my brain around document format db’s so apologies if my question is formatted incorrectly.

I’ve completed this course and although I hit a few issues on the way through, managed to find/undo/correct the process - primarily down to accidentally skipping a few chapters. However I’m trying to understand the following:

I have a 2 shard setup (as per the example) with a config server replication set and a single mongos looking at the config server. I can create a new db and have it sharded without a problem, but what if I don’t want to have the db sharded. Where does the data get stored?

I connect to mongos, use myNewDB, myNewDB.createCollection(“hello”) etc… I then add docs to this collection, but for the life of me can’t figure out where the data should get stored. Which one of the shards / replica sets? Or does it reside on the mongos? Before the sharding happens, where is the data?

I suspect if I knowingly want a non-sharded db, I should connect directly to one of the shard replication sets with a mongod but I’d like the definitive answer.

Thanks :slight_smile:

Suggest you work on this “accidental” skipping of chapters because this was discussed in the Sharding Architecture lecture. :slight_smile: Rewatch it and feel free to ask more questions.

The moment you have a shard, all connections should be made via the mongos. The config server handles where unsharded collections are stored… you’ll get to know this once you rewatch that lecture.

1 Like

Thanks for the reply - not sure if we’re talking at crossed purposes though - let me try again:

I understand that when I do a sh.enableSharding() followed by a sh.shardCollection(“mydb.mycollection”,{“myKey”:1}) the sharding magically happens and the existing db.collection is distributed across the shards.

My question is - where is the data stored before I enable the sharding? (assuming that I want my data sharded to begin with)

Again, if I’ve misunderstood - apologies.

Thanks

“Before sharding” == unsharded collection. This was discussed in the lecture previously mentioned.

ok, I guess we weren’t at crossed purposes :slight_smile: I did go back and do the lectures - I had to in order to complete the course work - maybe I missed that nugget. Thanks for the info - I’ll make sure I re-watch the lectures and take better notes.

:slightly_smiling_face: :+1:

Got it… thanks for the pointer. Have a great weekend.

And you! :beers: