Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply suggestions from code review #240

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ To use the MongoDB connector, you need to have a MongoDB server running and acce

### Setup a MongoDB server locally

#### Step 1: Install and run the MongoDB server

1. Download and install the MongoDB server from the [MongoDB download center](https://www.mongodb.com/try/download/community).

2. Follow the installation instructions provided in the download center.
Expand Down
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.8.5"
distribution-version = "2201.8.6"

[[package]]
org = "ballerina"
Expand Down
2 changes: 0 additions & 2 deletions ballerina/Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ To use the MongoDB connector, you need to have a MongoDB server running and acce

### Setup a MongoDB server locally

#### Step 1: Install and run the MongoDB server

1. Download and install the MongoDB server from the [MongoDB download center](https://www.mongodb.com/try/download/community).

2. Follow the installation instructions provided in the download center.
Expand Down
2 changes: 0 additions & 2 deletions ballerina/Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ To use the MongoDB connector, you need to have a MongoDB server running and acce

### Setup a MongoDB server locally

#### Step 1: Install and run the MongoDB server

1. Download and install the MongoDB server from the [MongoDB download center](https://www.mongodb.com/try/download/community).

2. Follow the installation instructions provided in the download center.
Expand Down
2 changes: 2 additions & 0 deletions ballerina/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public isolated client class Client {

# Closes the client.
#
# > **Note:** Use a single client instance for the lifetime of the application and close it when the application is done.
#
# + return - A `mongodb:Error` if the client is already closed or failed to close the client. `()` otherwise.
@display {label: "Close the Client"}
remote isolated function close() returns Error? = @java:Method {
Expand Down
12 changes: 10 additions & 2 deletions ballerina/collection.bal
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,16 @@

# Finds documents from the collection.
#
# > **Note:** Close the resulted stream once the operation is completed.
#
# + filter - The query filter to apply when retrieving documents
# + findOptions - The additional options to apply to the find operation
# + projection - The projection to apply to the find operation. If not provided, the projection will be generated
# based on the targetType
# + targetType - The type of the returned documents
# + return - A stream of documents which match the provided filter, or an error if the operation failed
isolated remote function find(map<json> filter = {}, FindOptions findOptions = {}, map<json>? projection = (),
typedesc<anydata> targetType = <>) returns stream<targetType, error?>|Error = @java:Method {
typedesc<record {|anydata...;|}> targetType = <>) returns stream<targetType, error?>|Error = @java:Method {

Check warning on line 70 in ballerina/collection.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/collection.bal#L70

Added line #L70 was not covered by tests
'class: "io.ballerina.lib.mongodb.Collection"
} external;

Expand All @@ -78,7 +80,7 @@
# + targetType - The type of the returned document
# + return - The document which matches the provided filter, or an error if the operation failed
isolated remote function findOne(map<json> filter = {}, FindOptions findOptions = {}, map<json>? projection = (),
typedesc<anydata> targetType = <>) returns targetType|Error = @java:Method {
typedesc<record {|anydata...;|}> targetType = <>) returns targetType|Error? = @java:Method {

Check warning on line 83 in ballerina/collection.bal

View check run for this annotation

Codecov / codecov/patch

ballerina/collection.bal#L83

Added line #L83 was not covered by tests
'class: "io.ballerina.lib.mongodb.Collection"
} external;

Expand All @@ -104,6 +106,8 @@

# Lists the indexes of the collection.
#
# > **Note:** Close the resulted stream once the operation is completed.
#
# + return - A stream of indexes, or an error if the operation failed
isolated remote function listIndexes() returns stream<Index, error?>|Error =
@java:Method {
Expand Down Expand Up @@ -156,6 +160,8 @@

# Retrieves the distinct values for a specified field across a collection.
#
# > **Note:** Close the resulted stream once the operation is completed.
#
# + fieldName - The field for which to return distinct values
# + filter - The query filter to apply when retrieving distinct values
# + targetType - The type of the returned distinct values
Expand Down Expand Up @@ -185,6 +191,8 @@

# Aggregates documents according to the specified aggregation pipeline.
#
# > **Note:** Close the resulted stream once the operation is completed.
#
# + pipeline - The aggregation pipeline
# + targetType - The type of the returned documents
# + return - A stream of documents which match the provided pipeline, or an error if the operation failed
Expand Down
4 changes: 3 additions & 1 deletion ballerina/tests/03_collection_tests.bal
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ isolated function testInsertAndFind() returns error? {
isolated function testFindOne() returns error? {
Database database = check mongoClient->getDatabase("testFindOneDB");
Collection collection = check database->getCollection("Movies");
Movie? actualResult = check collection->findOne();
test:assertEquals(actualResult, (), "Expected an empty result");
Movie movie = {name: "Interstellar", year: 2014, rating: 9};
check collection->insertOne(movie);
Movie? actualResult = check collection->findOne();
actualResult = check collection->findOne();
test:assertEquals(actualResult, movie);
check collection->drop();
check database->drop();
Expand Down
Loading
Loading