Skip to content

Files

Latest commit

429687c · Feb 14, 2017

History

History
109 lines (77 loc) · 8.11 KB

documentdb-view-scripts.md

File metadata and controls

109 lines (77 loc) · 8.11 KB
title description keywords services author manager editor documentationcenter ms.assetid ms.service ms.workload ms.tgt_pltfrm ms.devlang ms.topic ms.date ms.author
Azure DocumentDB portal tool: Script Explorer | Microsoft Docs
Learn about the DocumentDB Script Explorer, an Azure Portal tool to manage DocumentDB server-side programming artifacts including JavaScript stored procedures, triggers, and user-defined functions.
javascript editor
documentdb
kirillg
jhubbard
monicar
9d0620da-2449-4c17-82a4-24aaa46e9b3e
documentdb
data-services
na
na
article
02/14/2017
kirillg

Create and run stored procedures, triggers, and user-defined functions using the DocumentDB Script Explorer

This article provides an overview of the Microsoft Azure DocumentDB Script Explorer, which is a JavaScript editor in the Azure portal that enables you to view and execute DocumentDB server-side programming artifacts including stored procedures, triggers, and user-defined functions. Read more about DocumentDB server-side programming in the Stored procedures, database triggers, and UDFs article.

Launch Script Explorer

  1. In the Azure portal, on the left navigation, click Azure DocumentDB icon NoSQL (DocumentDB).

    If NoSQL (DocumentDB) is not visible, click More Services at the bottom, and then click Azure DocumentDB icon NoSQL (DocumentDB).

  2. In the resources menu, click Script Explorer.

    Screenshot of the Script Explorer command

    The Database and Collection drop-down list boxes are pre-populated depending on the context in which you launch Script Explorer. For example, if you launch from a database blade, then the current database is pre-populated. If you launch from a collection blade, then the current collection is pre-populated.

  3. Use the Database and Collection drop-down list boxes to easily change the collection from which scripts are currently being viewed without having to close and re-launch Script Explorer.

  4. Script Explorer also supports filtering the currently loaded set of scripts by their id property. Simply type in the filter box and the results in the Script Explorer list are filtered based on your supplied criteria.

    Screenshot of Script Explorer with filtered results

    [!IMPORTANT] The Script Explorer filter functionality only filters from the currently loaded set of scripts and does not automatically refresh the currently selected collection.

  5. To refresh the list of scripts loaded by Script Explorer, simply click the Refresh command at the top of the blade.

    Screenshot of Script Explorer refresh command

Create, view, and edit stored procedures, triggers, and user-defined functions

Script Explorer allows you to easily perform CRUD operations on DocumentDB server-side programming artifacts.

  • To create a script, simply click on the applicable create command within script explorer, provide an id, enter the contents of the script, and click Save.

    Screenshot of Script Explorer create option, showing the JavaScript editor

  • When creating a trigger, you must also specify the trigger type and trigger operation

    Screenshot of Script Explorer create trigger option

  • To view a script, simply click the script in which you're interested.

    Screenshot of Script Explorer view script experience

  • To edit a script, simply make the desired changes in the JavaScript editor and click Save.

    Screenshot of Script Explorer view script experience

  • To discard any pending changes to a script, simply click the Discard command.

    Screenshot of Script Explorer discard changes experience

  • Script Explorer also allows you to easily view the system properties of the currently loaded script by clicking the Properties command.

    Screenshot of Script Explorer script properties view

    [!NOTE] The timestamp (_ts) property is internally represented as epoch time, but Script Explorer displays the value in a human readable GMT format.

  • To delete a script, select it in Script Explorer and click the Delete command.

    Screenshot of Script Explorer delete command

  • Confirm the delete action by clicking Yes or cancel the delete action by clicking No.

    Screenshot of Script Explorer delete command

Execute a stored procedure

Warning

Executing stored procedures in Script Explorer is not yet supported for server side partitioned collections. For more information, visit Partitioning and Scaling in DocumentDB.

Script Explorer allows you to execute server-side stored procedures from the Azure portal.

  • When opening a new create stored procedure blade, a default script (prefix) will already be provided. In order to run the prefix script or your own script, add an id and inputs. For stored procedures that accept multiple parameters, all inputs must be within an array (e.g. ["foo", "bar"]).

    Screenshot of Script Explorer Stored Procedures blade to add input and execute a stored procedure

  • To execute a stored procedure, simply click on the Save & Execute command within script editor pane.

    [!NOTE] The Save & Execute command will save your stored procedure before executing, which means it will overwrite the previously saved version of the stored procedure.

  • Successful stored procedure executions will have a Successfully saved and executed the stored procedure status and the returned results will be populated in the Results pane.

    Screenshot of Script Explorer Stored Procedures blade, to execute a stored procedure

  • If the execution encounters an error, the error will be populated in the Results pane.

    Screenshot of Script Explorer script properties view. Execute a stored procedure with errors

Work with scripts outside the portal

The Script Explorer in the Azure portal is just one way to work with stored procedures, triggers, and user-defined functions in DocumentDB. You can also work with scripts using the the REST API and the client SDKs. The REST API documentation includes samples for working with stored procedures using REST, user defined functions using REST, and triggers using REST. Samples are also available showing how to work with scripts using C# and work with scripts using Node.js.

Next steps

Learn more about DocumentDB server-side programming in the Stored procedures, database triggers, and UDFs article.

The Learning path is also a useful resource to guide you as you learn more about DocumentDB.