[GODRIVER-1707] Inbuilt Support For Getting Keys in a Sub Document. Created: 05/Aug/20 Updated: 17/Aug/20 Resolved: 17/Aug/20 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | API |
| Affects Version/s: | 1.5.0 |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Shantanu Bansal | Assignee: | Divjot Arora (Inactive) |
| Resolution: | Won't Do | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Hi, We should support an inbuilt capability in the mongo driver to fetch the distinguished keys in a sub-document , this will be very handy just to have keys from the driver it self. |
| Comments |
| Comment by Divjot Arora (Inactive) [ 17/Aug/20 ] | |||||||||||
|
shantanubansal05@gmail.com Glad to hear that you have this working in your application. As I mentioned before, we don't think this is a very common use case and are therefore going to hold off on adding it to the driver right now. I'm going to close this ticket, but we can revisit and potentially open it again if we see this use case come up again from other users. – Divjot | |||||||||||
| Comment by Shantanu Bansal [ 16/Aug/20 ] | |||||||||||
|
Hi @Divjot, | |||||||||||
| Comment by Divjot Arora (Inactive) [ 14/Aug/20 ] | |||||||||||
|
I don't think this is something we want to add to the driver's public API because it's not a common use case and users will have different requirements. Some may want a list of only top-level keys. Others might want a list of all keys, where nested ones are in the format "topLevelKey.nestedKey". I've written up some code using FindOne to do this that you can migrate to your application: https://gist.github.com/divjotarora/27dfabb358771f526f661a9ec79f9f43. The one thing I noticed is that our bson.Raw type has a method to get a slice of Elements, which are key/value pairs, and a method to get just a slice of values, but not one to get a slice of keys, so there's an extra loop required in the code to get the keys from the elements. If you think it would help reduce complexity a bit, I can file a ticket to add a bson.Raw.Keys method. – Divjot | |||||||||||
| Comment by Shantanu Bansal [ 14/Aug/20 ] | |||||||||||
|
It depends on how we want to do it. The approach should be optimized. Q.). Do you want to get a list of keys from a specific document in a collection? Q.). would it be reasonable to first run Collection.Find or Collection.FindOne to get the document and then creating a slice of keys in the application/driver or does your use case require getting a list of keys directly from the server? | |||||||||||
| Comment by Divjot Arora (Inactive) [ 14/Aug/20 ] | |||||||||||
|
Hi shantanubansal05@gmail.com, I'd like to get a few more details before I make suggestions. Do you want to get a list of keys from a specific document in a collection? Or a list of keys of documents? If it's for a specific document, would it be reasonable to first run Collection.Find or Collection.FindOne to get the document and then creating a slice of keys in the application/driver or does your use case require getting a list of keys directly from the server? – Divjot
| |||||||||||
| Comment by Shantanu Bansal [ 14/Aug/20 ] | |||||||||||
|
Hi @Divjot, What I mean is we should be able to fetch the keys in the document or sub-document.
The abstraction should return me: If I search at the root level:
if queried at key3
Same goes for Values | |||||||||||
| Comment by Divjot Arora (Inactive) [ 10/Aug/20 ] | |||||||||||
|
Hi shantanubansal05@gmail.com, I didn't quite follow the request in the description. Can you provide a complete minimal example of a stored document and what information you'd like to get from it? If possible, it'd also be helpful to know which of the driver's currently exported methods you'd like to use to get this information. – Divjot |