I'm currently building an application which makes heavy use of JSONB in PostgreSQL. After a while of searching I was unable to find any solution to people's questions about distinct JSONB keys across an entire table. Here are my findings and I hope it helps someone else.
Today, I attended the workshops leading up to the MongoDB UK event and learned so much from the amazing solutions experts over at 10gen. I can't wait to apply everything I learned such as replica sets, sharding and forward planned Schema Design. I say Schema Deisgn, but since Mongo is a Schema-less database I actually mean an implied data structure on how to highly optimize applications for different use cases. Before attending I had intermediate understanding of how mongo worked in a production environment, but now I feel confident I could multiple machines, back them up and shard them with ease. It was also quite fun being a physical shard as part of Chris‘s role play example which helped to visual how data is actually managed and passed around the machines. I'm even more excited for MongoDB UK tomorrow, which is of course, the main event. With speakers from AOL, Nokia, Cloud Foundry and gov.uk I'm sure there will be some amazing use cases to be learned from. I'll hopefully try and getting some posts written while I'm there tomorrow, and maybe even write up some coding examples from what I learn. Also looking forward to the Sharded pub crawl afterwards, but let's not tell the boss about that one!
Here is a small script I whipped up while I was bored in the Travelodge waiting for #MongoDBUK. It's basically a drop in script to make sure MongoDB is installed with the default settings, and up to date. Very simple, but it saves running the commands manually each time. I may update this in the future when I find a better way to check if a key is already added before always inserting it #!/usr/bin/env sh # Sudo is required to install everything properly if [ "$(whoami)" != "root" ]; then echo "You need to use sudo to run this command" exit 0; fi echo "Installing MongoDB, please be patient, this could take a few minutes.." REPOSOURCE="deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" REPOFILE=/etc/apt/sources.list # Make sure packages are up to date and key exists apt-get update -qq && sudo apt-get upgrade -qq -y apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 # Append to repo if ! grep -Fxq "$REPOSOURCE" $REPOFILE then echo ": Adding $REPOSOURCE to $REPOFILE" echo "$REPOSOURCE" >> $REPOFILE apt-get update -qq fi # Run install apt-get install -y mongodb-10gen I normally put this in my home folder at ~/install-mongodb then run it using sudo ./install-mongodb. Note that sudo is actually a requirement, and the script will warn you if it you don't have root permissions. I will add more scripts in the next few hours as I go through the MongoDB UK workshops to have simple ways of switching configs for different scenarios and replacing the defaults to enable auth, for example. If you have any cool things you'd like me to write about regarding MongoDB please feel free to ask in the comments.