Skip to content

How can I obtain the JSON of a document given the item id? #370

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

Closed
sdg002 opened this issue May 20, 2020 · 3 comments · Fixed by #383
Closed

How can I obtain the JSON of a document given the item id? #370

sdg002 opened this issue May 20, 2020 · 3 comments · Fixed by #383
Assignees
Labels
enhancement The issue is an enhancement request. in progress The issue is being actively worked on by someone.

Comments

@sdg002
Copy link

sdg002 commented May 20, 2020

Issue

Before submitting your issue for the CosmosDB project, please take a moment to
provide the following details:

  • [5.1.1 ] Version of PowerShell you're using
  • [ISE ] PowerShell host you're using (eg. Console Host, ISE, Visual Studio)
  • [Windows 10 ] Operating system you're running
  • [ 3.7.0 ] Version of CosmosDB PowerShell Module you're using (use Get-Module -Name CosmosDB)
    Thanks for contributing your feedback and support! You can optionally submit a
    Pull Request against this project, if you have a fix you'd like to share.

Scenario

I would like to dump documents from my collection using a query into a physical folder. I would like to make some minor changes and then save them back.

Get-CosmosDbDocument

This worked well. But, it gave me a tabular result set - which is also very useful in other scenarios.

Thanks,
Sau

@PlagueHO
Copy link
Owner

Hi @sdg002, do you want to just return the RAW JSON of the document, rather than the document object?

You could just convert that to json using ConvertTo-Json - e.g. Get-CosmosDbDocument -Context $cosmosDbContext -CollectionId 'MyNewCollection' -Id $documents[0].id -PartitionKey $documents[0].id | ConvertTo-Json -Depth 20.

However, I'm assuming you're probably wanting the document "exactly" as it is returned from Cosmos DB - is that correct? In which case I could easily implement a -Raw parameter that would just return the RAW json - would that address your requirement?

@sdg002
Copy link
Author

sdg002 commented May 22, 2020

A parameter like -Raw might work well.

Or, a new purpose built cmdlet like Get-CosmosDbDocumentJson so that the intent is very clear to the consumer and there is no confusion with Get-CosmosDbDocument which is already doing a great job.

@PlagueHO
Copy link
Owner

Great Idea - I'll use the Get-CosmosDbDocumentJson. What I can do is actually just make Get-CosmosDbDocument a wrapper around Get-CosmosDbDocumentJson which will eliminate any code duplication.

I'll get onto this later today.

@PlagueHO PlagueHO self-assigned this May 30, 2020
@PlagueHO PlagueHO added enhancement The issue is an enhancement request. in progress The issue is being actively worked on by someone. labels May 30, 2020
PlagueHO added a commit that referenced this issue May 31, 2020
Added Get-CosmosDbDocumentJson function - Fixes #370
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is an enhancement request. in progress The issue is being actively worked on by someone.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants