| Create a new document database |
11:25 |
set personDB = ##class(%DocDB.Database).CreateDatabase("Person") |
| Create new properties to allow you to search on the property and index it |
11:25 |
do personDB.%CreateProperty("FirstName","%String","firstName",0)
do personDB.%CreateProperty("LastName","%String","lastName",1) |
| Sample dynamic abstract object using JSON notation |
12:49 |
set thisPerson = {"id":"1","firstName":"Thomas","lastName":"Andersen","addresses":[{"line1":"100 Some Street","line2":"Unit 1","city":"Seattle","state":"WA","zip":98012}],"contactDetails":[{"email":"thomas@anderson.com"},{"phone":"+1 555 555-555","extension":5555}]} |
| Transform dynamic abstract object to JSON string |
12:49 |
set thisPersonJSON = thisPerson.%ToJSON() |
| Accepts a JSON string and inserts it into the document database |
12:49 |
do personDB.%FromJSON(thisPersonJSON) |
| Instantiate an instance of the Document class |
13:35 |
set personDB = ##class(ISC.DM.Person).%New() |
| Set the JSON structure to the %Doc property of the document class |
13:35 |
set personDB.%Doc = {"id":"1","firstName":"Thomas","lastName":"Andersen","addresses":[{"line1":"100 Some Street","line2":"Unit 1","city":"Seattle","state":"WA","zip":98012}],"contactDetails":[{"email":"thomas@anderson.com"},{"phone":"+1 555 555-555","extension":5555}]}
write personDB.%Save() |
| Instantiate Document object |
14:40 |
set db=##class(%DocDB.Database).%GetDatabase("Person") |
| Search for document |
14:40 |
set result=db.%FindDocuments(["firstName","Bill","="])
write result.%ToJSON() |