Skip to content

Mongo and Grasshopper

Thomas Edward Kingstone edited this page Sep 7, 2023 · 5 revisions

MongoAdapter

Using Mongo with Grasshopper can be useful if you want to store a lot of data or use the data you already have stored in a script.

To create a MongoAdapter in Grasshopper you need to use BHoM. Either search for MongoAdapter or use CreateAdapter and right click your way to a MongoAdapter. In the adapter you need to specify a serverName, databaseName and collectionName.

From this adapter you can use the Pull or Push components to get data to and from Mongo.

mongo

Requests

To filter your data when using the Pull component you can make a request. To do so you need to use a CustomRequest component. Either search for CustomRequest or use CreateRequest and right click your way to Data, Requests, CustomRequest.

Create a panel and write your request there. For example if you want to get everything that has a ResultCase as 100 you will write: {$match:{"ResultCase":100}} in your panel. See MongoDB queries in a Nutshell for more queries.

mongo2

Pipelined Requests

To use requests that need to be pipelined, put each request with each other in a list, feed it into a CustomRequest per line, then feed that into a BatchRequest

For example, if you wanted to only get documents that have a ResultCase as 100, and only needed the ResultData field, then you would construct it like this:

mongo3