ballerina-platform / ballerina-library

The Ballerina Library
https://ballerina.io/learn/api-docs/ballerina/
Apache License 2.0
136 stars 64 forks source link

Conversion error when accessing array of primitives in MongoDB using Ballerina #7060

Open sagini18 opened 1 month ago

sagini18 commented 1 month ago

Description: When trying to access a MongoDB collection that contains an array of primitive values using the find() method in Ballerina, I encountered a conversion error.

Affected Versions: Ballerina 2201.10.1 (Swan Lake Update 10)

Error Occured: image

Expected Output image

Sample Code:


public type User record {|
    readonly string id;
    string name;
    string email;
    string[] subject_ids?;
    string[] followers_ids?;
    string[] following_ids?;
    string[] requested_ids?;
    string[] requested_by_ids?;
    boolean is_deleted = false;
    string role;
|};

resource function get users() returns models:User[]|error {
    mongodb:Collection users = check self.db->getCollection("users");
    stream<models:User, error?> resultStream = check users->find();
    return check from User user in resultStream
        select user;
}