diff --git a/examples/workflows/query_mongo.yaml b/examples/workflows/query_mongo.yaml new file mode 100644 index 000000000..8baf1693f --- /dev/null +++ b/examples/workflows/query_mongo.yaml @@ -0,0 +1,21 @@ +id: query-mongodb +name: Query MongoDB +description: Querying MongoDB + +triggers: +- type: manual +steps: +- name: mongodb-step + provider: + config: '{{ providers.mongo }}' + type: mongodb + with: + # Please note that argument order is important for MongoDB queries. + query: | + { + "find": "mycollection", + "filter": { + "name": "First Document" + } + } + single_row: true \ No newline at end of file diff --git a/keep/providers/mongodb_provider/mongodb_provider.py b/keep/providers/mongodb_provider/mongodb_provider.py index f403df3cb..8b923474c 100644 --- a/keep/providers/mongodb_provider/mongodb_provider.py +++ b/keep/providers/mongodb_provider/mongodb_provider.py @@ -160,6 +160,9 @@ def _query( Returns: list | tuple: list of results or single result if single_row is True """ + if type(query) is str: + query = json.loads(query) + client = self.__generate_client() database = client[self.authentication_config.database] results = list(database.cursor_command(query))