I'm encountering an error with the Ballerina programming language while querying data from my MongoDB using the find function. The error message I'm getting is: 'cannot infer type for parameter 'rowType'. I have also attached an image of my query method for reference. Can you assist me in resolving this issue?"
This is my code line.
map<json>[] response = check self.mongoClient->find("stores", (), search_query)
Please find the API doc related to the find
operation
https://lib.ballerina.io/ballerinax/mongodb/4.3.0#Client
Its return type is stream<rowType, error?> | Error
This sample might be useful for you https://github.com/ballerina-platform/module-ballerinax-mongodb/blob/08170e793ac0fb1a642a5a441621968e5134c57d/mongodb/samples/query.bal#L42 (but this is a little bit old)
We can do something like this:
type Store {
string name;
string address;
anydata...;
}
stream<Store, error?> found = check mongoClient->find("stores", filter = {name: "Joe Market"});
Store
is the type of record we are expecting from the collection.