0

In the data service project in Wso2 Integration Studio, I want to query from mongo DB and print the result.I cannot run a data containing # character through wso2 integration studio. My query is running via Mongo Compass.When I query the data that does not contain # characters, it works in wso2 integration studio.

The data in mongo is as follows:

{
  "_id": {
    "id": "urn:ngsi-ld:Building:47445",
    "type": "https://uri.fiware.org/ns/data-models#Building",
    "servicePath": "/"
  }
}

Below is my query that pulls the data from mongo in wso2:

<expression>
    collectionName.count({"_id.type": 'https://uri.fiware.org/ns/data-models#Building'})
</expression>

The error I get is this:

Caused by: java.lang.IllegalArgumentException: Not enough parameters passed to query: {"_id.type": 'https://uri.fiware.org/ns/data-models#Building'}
ycr
  • 12,828
  • 2
  • 25
  • 45
Ahmet Kalem
  • 113
  • 6

1 Answers1

0

# denotes an input parameter mapping in a Mongo query, Hence it's mandatory to parse an input parameter to the query if you have a #. One way to get around this is to remove the # when inserting the record. Another option is to use a regex pattern like below to count the records.

collectionName.count({'_id.type': {'$regex': 'data-models.*.Building'}})

You can read more on regex patterns here.

ycr
  • 12,828
  • 2
  • 25
  • 45