Node

Type {{#dataTypeArticle objectTypeId}}{{objectTypeId}}{{/dataTypeArticle}}
Datastore Type {{#dataTypeArticle datastoreTypeId}}{{datastoreTypeId}}{{/dataTypeArticle}}
Supports {{#article "security/authorities"}}authorities{{/article}}, {{#article "security/permissions"}}permissions{{/article}}, {{#article "transfer"}}transfer{{/article}}

Configuration

The node configuration contains system and custom properties. You can write your own properties as you see fit. However, system properties should be left alone as they are read-only.

The following table presents you the system properties.

Node Properties

Property Type Default Read-Only Description
_features object Read-Only This object contains all of the configuration for features which have been applied to this node instance. Feature configurations are keyed by feature QName.
_qname text Read-Only The QName for this node instance.
_type text Read-Only The QName for the type of this node.

Any system properties that are shown to be Read-Only are not modifiable on calls to create() or update(). Anything else is fair game.

Create a Node

You can create as many nodes in a branch as you like. By default, nodes are empty JSON documents. They are also disconnected from any other nodes.

Creating a node is as simple as:

```` // assume we have a branch var branch = ...;

// create node branch.createNode();

<p>
    The example above creates an empty node.  We can also pass in JSON that we want to store onto the node.
    <br/>
    <br/>
    Here is an example where we create an "album" node.  We store the title of the album, the artist who
    recorded it and the year it was released.
</p>

// assume we have a branch var branch = ...;

// create node branch.createNode({ "title": "Baby Blue", "artist": "Mary Lou Lord", "year": 2004 }).then(function() { console.log("Successfully created node, id: " + this.getId()); });




<!-- UPDATE -->

<h2 id="update">Update a Node</h2>
<p>
    You can update any of the non-system properties of a node.  You can also add your own custom properties.
</p>

// assume we have a node var node = ...;

// update some properties node.set("year", 2005); node.update();




<!-- DELETE -->

<h2 id="delete">Delete a Node</h2>
<p>
    When you delete a node, the node is marked as deleted on the tip changeset.  Effectively, it is deleted,
    however repositories allow you to restore (or rewind) in case you make a mistake.  Your previous edits and
    versions of the node are preserved.
    <br/>
    <br/>
    Here is an example of a node deletion:
</p>

// assume we have a node var node = ...;

// delete it node.del();





<!-- READ -->

<h2 id="read">Read a Node</h2>
<p>
    You can read a node by its ID or its QName.
</p>

// assume we have a branch var branch = ...;

// assume a node id var nodeId = "4b5b685c980c10f98beb";

// assume a qname var qname = "custom:album";

// here we read by node ID branch.readNode(nodeId).then(function() { console.log("Found node: " + this.get("title")); });

// here we read by QName branch.readNode(qname).then(function() { console.log("Found node: " + this.get("title")); });




<!-- SEARCH -->

<h2 id="list">Search for Nodes</h2>
<p>
    By default, all of nodes you put into a Cloud CMS branch are indexed for full-text search.  The JSON content
    of your node is indexed as well as any attachments.  If you upload a PDF document, for example, Cloud CMS will
    extract any tokens from the PDF document and make those searchable.
    <br/>
    <br/>
    Thus, you have automatic full-text search for everything you drop into a Cloud CMS repository.
    <br/>
    <br/>
    Here is an example of a simple full text search:
</p>

// assume we have a branch var branch = ...;

// find all nodes with the word "mary" in it branch.searchNodes("mary").then(function() { console.log("Found a node: " + this.getId()); });

<p>
    As you can imagine, the set of results can be pretty large.  You can utilize pagination to reduce the traffic
    over the wire and enhance performance.
</p>

// assume we have a branch var branch = ...;

// find all nodes with the word "mary" in it branch.searchNodes("mary", { "limit": 10, "skip": 20, "sort": { "title": -1 } }).then(function() { console.log("Found a node: " + this.getId()); });

<p>
    Cloud CMS utilizes <a target="_blank" href="http://www.elasticsearch.org/">Elastic Search</a> for full-text
    search and indexing.  As such, you can write much more powerful full-text search queries against the JSON
    of your documents.  The full JSON object is indexed.  Thus, you can utilize the
    <a target="_blank" href="http://www.elasticsearch.org/guide/reference/query-dsl/">Elastic Search Query DSL</a>
    to define more advanced queries.
    <br/>
    <br/>
    Here is an example that uses the Elastic Search Query DSL and also applies some pagination:
</p>

// assume we have a branch var branch = ...;

// define the query // this is a wildcard search // this will find "mary" but may also find "matt" var query = { "wildcard" : { "artist" : "ma*" } };

// run the query branch.searchNodes(query, { "limit": 10, "skip": 20, "sort": { "title": -1 } }).then(function() { console.log("Found a node: " + this.getId()); });




<!-- QUERY -->

<h2 id="query">Query for Nodes</h2>
<p>
    You can run custom queries against your nodes to find exactly what you're looking for.
    Here is a query that looks for nodes whose field <code>artist</code> is <code>Mary Lou Lord</code>.
</p>

// assume we have a repository var repository = ...;

repository.queryNodes({ "artist": "Mary Lou Lord" });

<p>
    Here is that same query followed by an iteration over the result map.
</p>

// assume we have a repository var repository = ...;

repository.queryNodes({ "artist": "Mary Lou Lord" }).each(function() { console.log("Found an album called: " + this.get("title")); });

<p>
    Cloud CMS utilizes the MongoDB query syntax under the hood.  As such, you can really go to town.
    You're able to express queries with some pretty rich complexity.
    <br/>
    <br/>
    Here is a query that finds all albums created between the years 2002 and 2006.
</p>

// assume we have a repository var repository = ...;

// define a query var query = { "artist": "Mary Lou Lord", "year": { "$gt": 2002, "$lt": 2006 } };

// define our pagination var pagination = { "limit": 10, "skip": 20, "sort": { "title": -1 } };

repository.queryNodes(query, pagination).each(function() { console.log("Found an album called: " + this.get("title")); });