docs.intersystems.com
Home  /  Application Development: Additional Options  /  Using Document Database (DocDB)  /  Managing Documents


Using Document Database (DocDB)
Managing Documents
[Back]  [Next] 
InterSystems: The power behind what matters   
Search:  


InterSystems IRIS Data Platform™ DocDB supplies class methods that enable you to work with DocDB from ObjectScript. For further details on invoking JSON methods from ObjectScript, refer to the Using JSON manual.
This chapter describes methods to perform the following operations:
Get a Document Database: %GetDatabase()
To get a document database in the current namespace, invoke the %GetDatabase() method:
  SET db = ##class(%DocDB.Database).%GetDatabase("Person")
  WRITE db
Count Documents in a Database: %Size()
To count the number of documents in a database, invoke the %Count() method:
  SET doccount = db.%Size()
  WRITE doccount
Find Documents in a Database: %FindDocuments()
To find one or more documents in a database by data value and return the document(s). This syntax returns the entire document:
  SET result = db.%FindDocuments(["firstName","Bill","="])
  WRITE result.%ToJSON()
To return only some of the values in returned documents you use a projection. A projection is an array listing the keys for which you wish to return the corresponding values:
  SET result = db.%FindDocuments(["firstName","Bill","="],["%DocumentID","firstName"])
  WRITE result.%ToJSON()
To return only a specified number of matching documents, you can specify a limit:
  SET result = db.%FindDocuments(["firstName","Bill","="],["%DocumentID","firstName"],{"limit":5})
  WRITE result.%ToJSON()
This returns at most 5 documents.
Delete a Document: %DeleteDocument()
You can delete documents from a database either by documentID or by data selection criteria.