Home > Mobile >  Error when querying records with # character in WSO2 Data service via MongoDD
Error when querying records with # character in WSO2 Data service via MongoDD

Time:01-16

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'}

CodePudding user response:

# 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.

  • Related