Caltech Library logo

Basics

This is an example of creating a dataset called fiends.ds, saving a record called “littlefreda.json” and reading it back.

   dataset init fiends.ds
   export DATASET="fiends.ds"
   dataset create littlefreda '{"name":"Freda","email":"little.freda@inverness.example.org"}'
   for KY in $(dataset keys); do
      echo "Path: $(dataset path $KY) 
      echo "Doc: $(dataset read $KY)
   done

Notice that the command dataset init fiends.ds will emmit the export DATASET="fiends.ds" line. You can cut and paste this into your terminal session to set the default dataset you’re using. This will save you resorting to the -c or -collection option which makes the command quite long.

Now check to see if the key, littlefreda, is in the collection

   dataset haskey littlefreda

You can also read your JSON formatted data from a file or standard input. In this example we are creating a mojosam record and reading back the contents of fiends.ds

   dataset -i mojosam.json create mojosam
   for KY in $(dataset keys); do
      echo "Path: $(dataset path $KY) 
      echo "Doc: $(dataset read $KY)
   done

Or similarly using a Unix pipe to create a “capt-jack” JSON record.

   cat capt-jack.json | dataset create capt-jack
   for KY in $(dataset keys); do
      echo "Path: $(dataset path $KY) 
      echo "Doc: $(dataset read $KY)
   done