Error in WSO2 when writing MongoDB query containing "Aggregate" - mongodb

I am working with WSO2 EI 6.5.
I have MongoDB 3.2 installed on my machine.
Whenever I write a Mongodb query containing the operator "aggregate", I get the following error when I call the service " Unknown MongoDB operation 'aggregate' ".
My service needs to link Collections A (id1, fieldA1, fieldA2) and B (id2, fieldB1, fieldB2) for fieldB1 = fieldA2.
Can someone advise?
Thanks.

Related

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

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

Getting error for query in mongo 3.6.22 which works fine in 4.4.3 enterprise

I'm getting an error for mongo query in mongo version 3.6.22 error as follows
MongoError: arguments to $lookup must be strings, let: { profileIds:
"$ProfileIDs" } is type object
But this same query works fine in mongo version 4.4.3 enterprise, and the ProfileIDs are String
3.6 does not support let in $lookup. You need to write your query differently.

Spring Data Embedded Mongo: 'unknown top level operator: $expr' on server

when I run any query containing $expr operation against Embedded Mongo I get the following error:
UncategorizedMongoDbException: Query failed with error code 2 and error message 'unknown top level operator: $expr' on server
The command runs fine against my local instance of mongo.
This is the version of embedded mongo I'm using: testCompile('de.flapdoodle.embed:de.flapdoodle.embed.mongo:2.1.1')
This is the query for reference:
Criteria.where("$expr").ne(Arrays.asList("$val.a", "$val.b"))
Found it.
flapdoodle was downloading a version of Mongodb that didn't have that feature by default.
You can override the default version by specifying the following in your
src/test/resources/application.properties
spring.mongodb.embedded.version=3.6.4
spring.mongodb.embedded.features=SYNC_DELAY,NO_HTTP_INTERFACE_ARG,ONLY_WITH_SSL

How to read from a replicaset mongo by mongodb-erlang

1. {ok,P}= mongoc:connect({rs, <<"dev_mongodb">>, [ "dev_mongodb001:27017", "dev_mongodb002:27017"]}, [{name, mongopool}, {register, mongotopology}, { rp_mode, primary},{ rp_tags, [{tag,1}]}], [{login, <<"root">>}, {password, <<"mongoadmin">>}, {database, <<"admin">>}]).
2. {ok, Pool} = mc_topology:get_pool(P, []).
3. mongoc:find(Pool, {<<"DoctorLBS">>, <<"mongoMessage">>}, #{<<"type">> => <<"5">>}).
I used latest version in github, and got an error at step 3.
It seems my selector is not valid, is there any example of how to use mongodb-erlang ?
My mongodb version is 3.2.6, auth type is SCRAM-SHA1.
mongoc:find(Pool, <<"mongoMessage">>, #{<<"type">> => <<"5">>}).
I tried this in rs and single mode, still got this error.
Is there any other simple way to connect and read?
I just need to read some data once from mongo when my erlang program start, no other actions.
Todays version of mongo does not support tuple colldb due to new query api introduced in mongo 2.6
You should connect to DoctorLBS database instead, and than use
mongoc:find(Pool, <<"mongoMessage">>, #{<<"type">> => <<"5">>}).

com.mongodb.MongoQueryException: Query failed with error code 13

We are getting com.mongodb.MongoQueryException:
> Query failed with error code 13 while connecting to MongDB trhough
> spring-data.
MongoDB version 3.x
Spring 4.1.6, mongo-java-driver - 3.0.2, spring-data-commons - 1.10.0.RELEASE, spring-data-mongodb - 1.7.0.RELEASE
Unable to run the find query on a collection.
I am able to view the collection on GUI using same credentials.
Any help would be appreciated.
Here is the full exception:
> org.springframework.data.mongodb.UncategorizedMongoDbException: Query
> failed with error code 13 and error message 'not authorized for query
> on <db.table>' on server xxx; nested exception is
> com.mongodb.MongoQueryException: Query failed with error code 13 and
> error message 'not authorized for query on db.table on server xxx
> at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:96)
> at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2002)
> at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:1885)
Check mongo XSD for 2.6 vs 3.0 java drivers, they are different - it seems you still use old way to authenticate.
<mongo:db-factory dbname="${mongo.database}" username="${mongo.user}"
password="${mongo.pwd}" mongo-ref="mongo"/>
This works with 2.6 java driver only, not with 3.0 java driver.
Use this mongo-client-option with credentials attribute.
<mongo:mongo-client replica-set="${mongo.replica-set}" credentials="you need to put here user/password with specific DB">
The comma delimited list of username:password#database entries to use for authentication. Appending ? uri.authMechanism allows to specify the authentication challenge mechanism. If the credential you're trying to pass contains a comma itself, quote it with single quotes: '…'.