Menu
#Quick start
Start a server with a throwaway data directory and connect to it:
FERRITE_DATA=/tmp/ferrite_try ferrite_db 127.0.0.1:7878nc 127.0.0.1 7878Type one request per line. Each line is answered with one line of JSON. The replies below are what the server sends for these exact lines, except that the ids will differ.
#Choose a database
{"cmd":"use","db":"shop"}{"db":"shop","ok":true}The database is made by the first write to it. The use stays for the rest of the connection.
#Insert
{"cmd":"insert","collection":"users","doc":{"name":"Dylan","age":25,"address":{"city":"Leeds"}}}{"id":{"$oid":"6b12e5a20000c4e849f2795a"},"ok":true}Several at once, all or nothing:
{"cmd":"insert","collection":"users","docs":[{"name":"Ann","age":31,"address":{"city":"York"}},{"name":"Bob","age":17,"address":{"city":"Leeds"}}]}The reply has ids, a list.
#Find
{"cmd":"find","collection":"users","filter":{"age":{"$gt":18}},"sort":{"age":-1},"limit":10}The reply is {"docs":[...],"ok":true} with Ann first and then Dylan. A path like "address.city" reaches into a nested document:
{"cmd":"count","collection":"users","filter":{"address.city":"Leeds"}}{"count":2,"ok":true}#Update
{"cmd":"update","collection":"users","filter":{"name":"Dylan"},"update":{"$inc":{"age":1}},"limit":1}{"count":1,"ok":true}count is how many documents were changed. Without limit, an update changes every match.
#Aggregate
{"cmd":"aggregate","collection":"users","pipeline":[{"$match":{"age":{"$gte":18}}},{"$group":{"_id":"$address.city","people":{"$sum":1},"oldest":{"$max":"$age"}}},{"$sort":{"people":-1}}]}{"docs":[{"_id":"Leeds","oldest":26,"people":1},{"_id":"York","oldest":31,"people":1}],"ok":true}Both cities have one adult, so the order of the two between them is not meaningful here.
#Index
{"cmd":"createIndex","collection":"users","field":"address.city"}{"created":true,"ok":true}Equality and range filters on address.city now use the index instead of scanning the collection. See Indexes.
#Next
- Requests and replies for the shape of everything above
- Filters and updates for the operators
- Configuration before you run it for real