Using Mongoser

Post date: Jul 14, 2014 6:41:52 PM

Sensors can read and write to their respective database (this must be auto)

Users can read with passwd (created manually)

Common usage sequence of Mongoser. For more example, visit https://sites.google.com/site/mongodbjavarestserver/examples

For writers:

* Upload files, which creates <col>.chunks and <col>.files

curl -k -i "https://localhost:8081/gridfs/<db>/<col>?user=<userW>&passwd=<pwdW>&filename=1.wav" -XPUT --data-binary @1.wav -H"Content-Type:audio/wav"

where userW is the writer's username and pwdW is the writer's password. The "-k" option is to ignore self-signed certificate warning.

* Upload files with metadata in json in percent-coding format

curl -k -i "https://localhost:8081/gridfs/<db>/<col>?user=<userW>&passwd=<pwdW>&filename=1.wav&metadata=%7Bx:1%7D" -XPUT --data-binary @1.wav -H"Content-Type:audio/wav"

* Add metadata in <col>.files

curl -k -i "https://localhost:8081/write?dbname=<db>&colname=<col>.files&user=<userW>&passwd=<pwdW>" -XPOST --data-binary $'{filename:"1.wav"}\n{$inc:{metadata:1}}'

where --data-binary tells curl to NOT do any conversion, i.e. "\n"

* Add a document in a collection <col>

curl -k -i "https://localhost:8081/write?dbname=<db>&colname=<col>&user=<userW>&passwd=<pwdW>" -XPUT --data-binary '{filename:"1.wav", metadata:1}'

For readers:

* List all documents in a collection

curl -k -i "https://localhost:8081/query?dbname=<db>&colname=<col>&user=<userR>&passwd=<pwdR>"

* Read a record with condition

curl -k -i "https://localhost:8081/query?dbname=<db>&colname=<col>&user=<userR>&passwd=<pwdR>" -XPOST -d '{metadata: 1}'

where -d allows curl to perform auto-conversion, where there is none in this case. userR is the reader's username and pwdR is the reader's password.

* List file in a collection <col> through the Gridfs interface

curl -k -i "https://localhost:8081/gridfs/<db>/<col>?user=<userR>&passwd=<pwdR>&op=list"

* Get a file from <col>.chunks by filename via the Gridfs interface

curl -k -i "https://localhost:8081/gridfs/<db>/<col>?user=<userR>&passwd=<pwdR>&filename=1.wav" > tmp.wav