[JAVA-2401] Create an API for creating IndexOptions from Bson objects Created: 07/Dec/16  Updated: 28/Mar/17  Resolved: 28/Mar/17

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Tomasz Piskorski [X] Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 Description   

As a user I want to have an API for easy creating IndexOptions from Bson objects.

Given Bson object containing all the options I need - I have to individually map them into IndexOptions.



 Comments   
Comment by Jeffrey Yemin [ 26/Jan/17 ]

I'm inclined to close as Won't Fix, given that:

  1. There are numerous Options classes, and it wouldn't make sense to do this for just one. We'd have to do it for all.
  2. There is not always a clean mapping between options classes and a single BSON Document

Fundamentally, we don't expect a significant proportion of our users will have the requirement to configure options classes via BSON/JSON, and those that do can straightforwardly write their own code to map between the two.

Comment by Jeffrey Yemin [ 28/Dec/16 ]

There is a org.bson.BsonArray#parse method, but that's not going to help you transform each BsonDocument in the BsonArray into an instance of IndexOptions. You'd still have to write that code manually.

Another options is to use MongoDatabase.command() and construct the createIndexes command in your application.

Comment by Tomasz Piskorski [X] [ 22/Dec/16 ]

We store all indexes per collection in a single json file. So itrs an array of objects.
The format is:

[

{ keys:[...], options: [...] }

,
...
]

We wanted to move from mongo 2 to mongo 3 API.
In mongo 2 API there is, I could parse array of objects into DBObject list or something like that, the thing is we want to use the newer API.
In mongo 3 API theres no clean way of parsing this using built-in API.

Document.parse parses only single JSON object, lacking the functionality of parsing the array of objects. We used third party library on top of that.

Comment by Jeffrey Yemin [ 22/Dec/16 ]

Where is your application getting the Bson object that contains all the options you need?

If the driver provided this, it would have to do it for all the options classes in com.mongodb.client.model, so we'd really like to understand the use case for this request.

Generated at Thu Feb 08 08:57:06 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.