nrj
A Node.js client for RiakJson document store framework
Installation
npm install -g nrj
Usage
Creating / Referencing a Collection
Create a client, and reference a new or existing collection. Note: On the server side, the collection is only created, in any real sense, when either the first document is inserted, or the collection indexing schema is saved.
var riak_json = ;var client = riak_jsonClient; // default http host and portvar cities_collection = client;
Solr Schema Administration
You may set an optional Solr indexing schema for a RiakJson collection. If you do not set an explicit schema, and start inserting documents into a collection, RiakJson will attempt to infer a schema based on the document's structure (keep in mind, though, that the derived schema attempts to index every field in the document).
Supported Solr indexing field types:
string
(no spaces, think of a url slug)text
(spaces allowed)multi_string
(an array of strings, no spaces)integer
schema = cities_collection; // get a new CollectionSchema objectschema;schema;schema; // required: falseschema;schema;cities_collection;
You can now retrieve the stored schema (once RiakJson and Solr has had a chance to process it).
schema_fields = cities_collection// [{// name: "city",// type: "text",// require: true// }, {// name: "state",// type: "string",// require: true// }, {// name: "zip_codes",// type: "multi_string",// require: false// }, {// name: "population",// type: "integer",// require: false// }, {// name: "country",// type: "string",// require: true// }]
Reading and Writing Documents
You can now perform CRUD operations on JSON documents and collections:
var doc = 'nyc' city: 'New York' state: 'NY'; // key = 'nyc'collection; collection; // => {city: 'New York', state: 'NY'} collection; // => deletes the document at key 'nyc'
Querying RiakJson - find_one() and find_all()
See RiakJson Query Docs for a complete list of valid query parameters.
Unit Testing
npm test