hw5-queries.n1ql
. Important: make sure you can run your submission file all at once by running
cat hw5-queries.n1ql | cbqThis should produce a JSON object for each query result without errors.
export PATH="$PATH:/Applications/Couchbase Server.app/Contents/Resources/couchbase-core/bin"
export PATH="$PATH:/opt/couchbase/bin"
cbdocloader -u Administrator -p [your-password] -n 127.0.0.1:8091 -b mondial -s 100 mondial.jsonMake sure your PATH variable is correctly (so it can find cbdocloader), or your admin password is correct, and that the file mondial.json is accessible (cd or type the full path). If you are on a Mac and get an error relating to a snappy-c.h file, you will need to install the snappy library. If you have Homebrew, the command is
brew install snappy
.
cbqOn Windows: you can find file cbq.exe in C:\Program Files\Couchbase\Server\bin\cbq.exe. Open this executable file instead.
select y from mondial x unnest x.mondial.country y where y.name='Greece'; select y.["-car_code"] as car_code, y.name, ARRAY_LENGTH(y.province) as no_provinces from mondial x unnest x.mondial.country y where y.name='Greece'; select y.name, count(y.province) as no_provinces from mondial x unnest x.mondial.country y unnest y.province group by y.name; select y.name, y.height from mondial x unnest x.mondial.mountain y;There is no 'help': to exit, type CTRL/D. If you get the error message "No primary index on keyspace mondial. Use CREATE PRIMARY INDEX to create one." then you need to create one manually:
CREATE PRIMARY INDEX mondial_primary ON mondial USING GSI;mondial.json is small enough that you can browse it with a text editor to explore it structure.
hw5-extracredit.n1ql
, write a query using the NEST operator that answers question 7 but returns a list of mountain names and mountain heights for each country name. Do not do it using ARRAY_AGG. The staff isn't even sure how to do this.