Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space WBRIDGE and version 22.1
Hint_designer
PageDESIGNER:Querying MongoDB
TopicMongoDB Adapter

Use stereotype <<MongoDBAdapter>> on an action node to interact with a MongoDB and to insert, get and manipulate documents.

Multiexcerpt include
SpaceWithExcerptINTERNAL
MultiExcerptNamemongodb
PageWithExcerptINTERNAL:_examples_BRIDGE

Using action find you can retrieve data. MongoDB stores data in form of documents that are depicted in a JSON-like format. Queries always return one or more complete documents.

Multiexcerpt
MultiExcerptNamequerystring

For all actions that refer to existing documents, you need to provide a query string (queryString) to identify them. A query string contains all properties of the document you want to use for selection.
The simplest way to create a query string is to create an object having the structure of the document (queryData in the example above), and set all query values to this object.

Then, provide this object as queryString by converting it to JSON using classToJson().

A find action of a <<MongoDBAdapter>> returns either a result set or a handle.

NameTypeDescription
resultArray of StringAn array of all resulting documents in JSON format.The complete set of found documents in an array.
Array of <document class>

An array of objects of an xUML class representing the document structure.

Info

This only makes sense if you know the structure of the documents you are accessing.

handleMongoDBHandle

A handle to a result set.

This is helpful if

  • you expect a huge amount of documents being returned, and do not want to load the complete result set to the memory
  • you want to iterate over the result set one by one anyway, and e.g. only regard a subset of the result for further processing.

You need to process the result set one by one using fetch.

Refer to Action "find" and Action "fetch" for a detailed description of all parameters and options.

Selecting Output Data

MongoDB uses the concept of "projection" to define which properties should be selected from a document. The projection is supplied to the adapter call via the projection attribute of the MongoDBFindOptions.

The following rules apply to projections:

RuleExample
You can select dedicated properties.

{ name: 1 }

You can select all properties and omit dedicated properties.{ name: 0 }

You cannot mix both above mentioned rules. This will lead to an exception.

{ name: 1, company: 0 }
You can select properties from within a structure.{ address.street: 1 }
You cannot select all properties and omit dedicated properties from within a structure. This will be ignored. { address.street: 0 }

Sorting

You can sort the document list you get back from an adapter call by providing the sort attribute of MongoDBFindOptions.

Parameter sort contains the document properties to sort by. Value 1 is ascending sorting, value -1 is descending sorting. The order of JSON properties reflects the sort hierarchy.

Info

You cannot use classToJson() to build the sort string. With the sort string, the order of properties is relevant, and classToJson() does not guarantee that the order within the JSON string reflects the order of class attributesneed to escape the attribute name sort because there is an operation having the same name.

Otp
Floatingfalse

Rp

Children Display
pageMongoDB Adapter