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();
The example above creates an empty node. We can also pass in JSON that we want to store onto the node.
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.
// 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 a Node
You can update any of the non-system properties of a node. You can also add your own custom properties.
// assume we have a node
var node = ...;
// update some properties
node.set("year", 2005);
node.update();
Delete a Node
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.
Here is an example of a node deletion:
// assume we have a node
var node = ...;
// delete it
node.del();
Read a Node
You can read a node by its ID or its QName.
// 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 for Nodes
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.
Thus, you have automatic full-text search for everything you drop into a Cloud CMS repository.
Here is an example of a simple full text search:
// 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());
});
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.
// 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());
});
Cloud CMS utilizes Elastic Search 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 Elastic Search Query DSL to define more advanced queries.
Here is an example that uses the Elastic Search Query DSL and also applies some pagination:
// 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 for Nodes
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 artist
is Mary Lou Lord
.
// assume we have a repository
var repository = ...;
repository.queryNodes({
"artist": "Mary Lou Lord"
});
Here is that same query followed by an iteration over the result map.
// assume we have a repository
var repository = ...;
repository.queryNodes({
"artist": "Mary Lou Lord"
}).each(function() {
console.log("Found an album called: " + this.get("title"));
});
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.
Here is a query that finds all albums created between the years 2002 and 2006.
// 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"));
});