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
/* | |
* Find the active users who mention "sell out" in their profile. Of the three | |
* most recent registrants, order by most number of tags. | |
*/ | |
var query = cts.andQuery([ | |
cts.orQuery([ | |
cts.jsonPropertyValueQuery("isActive", true), | |
cts.jsonPropertyWordQuery("about", "sell out") // The text "sell out" or its stems | |
]), |
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
/* | |
* Insert some JSON generated from http://www.json-generator.com and http://hipsum.co, natch. | |
*/ | |
// Tell the transaction manager that we intend to update the database. | |
declareUpdate(); | |
var data = [ | |
{ | |
"id": 0, |
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
// utilities.sjs | |
// Library modules can require other library modules. | |
var o = require("../other.sjs"); | |
module.exports = { | |
// Maps the internal implementation to a public name. | |
doSomething: internalSomething | |
}; |
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
// Main module | |
var util = require("utilities.sjs"); | |
util.doSomething(); |
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
function* asObjects(itr) { | |
for(var doc of itr) { | |
yield doc.toObject(); | |
} | |
} | |
var a = []; | |
for(var obj of asObjects(fn.collection())) { | |
// Assumes you have JSON documents in the database with .name properties, as in the examples below. | |
a.push(obj.name = "Generated: " + obj.name); |
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
var itr = fn.collection(); | |
while (true) { // Loop until break | |
var item = itr.next(); // Advance the iterator | |
if(item.done) break; // If we're at the end, exit the loop | |
var user = item.value.toObject(); | |
// Do something with the object... | |
} |
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
// fn.collection(), and most things that interact with the database, returns a ValueIterator | |
// The ES6 for…of loop automatically iterates. | |
for (var doc of fn.collection()) { | |
var user = doc.toObject(); | |
// Do something with the object... | |
} |
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. |
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
declareUpdate(); | |
var user = { | |
"name": "Dave Cassel" | |
}; | |
xdmp.documentInsert( | |
'/dave-cassel.json', | |
user, | |
xdmp.defaultPermissions(), |
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
{ | |
"user": { | |
"personal": { | |
"userID": 38465, | |
"title": "Tech Adventurer" | |
}, | |
"experiences": [ | |
{ | |
"title": "Lead Adventurer", | |
"text": "experience description", |