Last active
September 14, 2015 15:13
-
-
Save dmcassel/90ea722941da9c74e134 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We need to call declareUpdate() to persist changes in the database. | |
declareUpdate(); | |
var uri = "/n81ff186a6c5290db.json"; | |
// cts.doc() returns a Document node or null, given a unique id (URI) | |
var user = cts.doc(uri) | |
.root // The root Node instance of the Document container. For a JSON document, likely an ObjectNode | |
.toObject(); // Turn any Node instance into JavaScript object. | |
// Update the "name" property to upper-case. Again, you don't need the preceding .toObject() | |
// if you just want to read the value. However, to update it you need to first convert it | |
// to a plain old JavaScript object with .toObject(). | |
user.name = user.name.toUpperCase(); | |
// Convert the plain old Object instance back into a Document node. | |
var node = xdmp.toJSON(user); | |
// You can read properties on Node instances, but you must convert to an object to update any aspect. | |
// Remember, xdmp.toJSON() creates a Document node, so you have to use .root to get the root ObjectNode. | |
node.root.name; | |
// …but you don't have to convert an object to a Node to persist it. | |
// Functions like xdmp.documentInsert() will automatically do the equivalent of xdmp.toJSON(user), above. | |
xdmp.documentInsert(uri, user, xdmp.defaultPermissions(), ["fake data"]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment