[JAVA-5274] Add method toJson() to class BsonArray Created: 20/Dec/23 Updated: 03/Jan/24 |
|
| Status: | Investigating |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Unknown |
| Reporter: | Steel Li | Assignee: | Ashni Mehta |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I will create a PR on GitHub to implement the feature. |
| Comments |
| Comment by Steel Li [ 03/Jan/24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi tom.selander@mongodb.com, we are migrating a system using MongoDB written by C#. In the system, we don't use concrete types to process data. There is an API used to find documents as following code:
But there is no toJson function in BsonArray or other BsonValue implemented classes such as BsonInt32, etc. in Java driver. If we need to create same API, we need to iterate documents then convert to JSON one by one and combine them.
If we have the toJson() function, we can use following code to implement it:
The worst is we have another API distinct, which can provide the distinct result.
But without the toJson() function, we cannot implement the API using Java since each element of the distinct result are just like BsonInt32, BsonInt64... but not BsonDocument. If we have the function, we can use following code to implement it:
Above are my user cases, and do you have a simple approach to implement my request regarding the code written by C#? | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Tom Selander [ 02/Jan/24 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi steelcg@outlook.com, This is not something we support currently because MongoDB server only supports arrays embedded within documents so this isn't supported in BSON. Can you describe what your use case is for this functionality? | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Steel Li [ 20/Dec/23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
the PR on GitHub: https://github.com/mongodb/mongo-java-driver/pull/1284 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by PM Bot [ 20/Dec/23 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi steelcg@outlook.com, thank you for reporting this issue! The team will look into it and get back to you soon. |