This group of packages contains every function you need when dealing with the unified data model, or MongoDB in general.
Document
This is the core package to use UDM with. It is designed to be able to handle most interaction you need with the database, using only five functions.
Example
use Document; // Build the document (usually you scrape real documents and put their information in this object) var doc = Document.new( "customPage", { "version": 2, "user": { "id": 54, "username": "lancelot34", "password": "IAmASafePassword" } }, [ { "version": 1, "user": { "id": 54, "username": "lancelot34", "password": "HelloWorld" } } ] ); // Save the document Document.save(doc);
If you run this code by itself, you will get a 'Definition for content type [CustomPage] not found' error message. That is why you need the following package once before saving any document.
ContentType
When Document.save
is executed to store a document, the document will first be validated with the stored content types. Defining content types is done with this ContentType package.
Example
use ContentType,Document; // Build the body var userDecorator = { "id": { "type": "NUMBER", "required": true }, "username": { "type": "STRING", "required": true }, "password": { "type": "STRING", "required": true } }; // Add to cache ContentType.decorator("user", userDecorator); // Define content type ContentType.save("customPage", ["user"]);
Mongo
This package provides 'the rest' of the functionality to interact with MongoDB. It is not strictly a UDM package, but grouped here anyway because UDM always uses MongoDB and MongoDB is in Xill generally always used with UDM.
Example
Say you want to remove all documents of a certain type:
use Mongo; use System; Mongo.connect("udm_default"); var query = { "contentType": "customPage" }; var result = Mongo.remove("assets", query); System.print("Deleted " :: result :: " documents.");