Querying DocumentDb for Inner results - azure-cosmosdb

I have a document with this structure:
[{
"id": "test",
"StudentRules": [
{
"id": "d8b730905",
"name": "Test",
"ruletype": "Allow",
"startdate": "5/7/2015 10:05:15 AM"
}
]
I need to write a query that will give me all the "StudentRules" for a given id "test".
I wrote this:
select * from json j where j.id = "test"
This returns the structure as the example above.
I am expecting this:
[
{
"id": "d8b730905",
"name": "Test",
"ruletype": "Allow",
"startdate": "5/7/2015 10:05:15 AM"
}
]
The idea is to have all the rules in a list which will be shown in an MVC application.
Any help is greatly appreciated.
Thanks in advance.
Regards.

You can use the JOIN keyword to form cross products with nested array elements:
SELECT Rule.id, Rule.name, Rule.ruletype, Rule.startdate
FROM root
JOIN Rule IN root.StudentRules
WHERE root.id = "test"
You may find looking at the sample queries on DocumentDB's query playground useful.

Related

Can't get the desired properties via JsonPath evaluate method

I have a json schema that marks special properties in need of processing and I want to query those via JsonPath.Evaluate.
Here's a part of the schema to illustrate the issue
{
"type": "object",
"properties": {
"period": {
"description": "The period in which the rule applies",
"type": "object",
"properties": {
"start": {
"type": "string",
"format": "date-time"
},
"end": {
"type": "string",
"format": "date-time"
}
},
"required": [
"start"
],
"x-updateIndicatorProperties": [
"start"
]
},
"productType": {
"type": "string"
},
"x-updateIndicatorProperties": [
"productType"
]
}
}
I want to get the the JsonPath of the "x-updateIndicatorProperties" properties, so that I can then query the actual properties to process.
For this example, the expected result would be
[
"$['properties']['x-updateIndicatorProperties']",
"$['properties']['period']['x-updateIndicatorProperties']"
]
I've been trying for a while to get a JsonPath expression that would query these properties.
Currently I'm just iterating all properties and filter them manually :
"$..*"
I've also tried using :
$..['x-updateIndicatorProperties']
This works. But it returns a lot of duplicates. For the example above, I get 5 results instead of the expected 2. Can be demonstrated here : https://json-everything.net/json-path
Assuming I can't influence the schema itself, only the code that traverses it,
can anybody help with an expression to get the expected results or any other way to achieve the same outcome?
The stack is JsonPath 0.2.0, .net 6 and system.text.json.
This was a bug in the library when parsing paths that use a recursive descent (..) into a quoted-property-name selector (['foo']). So it would happen for any path in the form $..['foo'].
I've fixed the issue and released version 0.2.1.

Artifactory: how can I obtain a complete dump of all fields for an artifact?

I'm interested in the value of one field (Module ID) but there seems to be no way of obtaining this specifically. A complete dump of all field values would also suffice but I haven't succeeded in finding a way to do that either. I've looked at and tried the searches available within the documentation here: https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API#ArtifactoryRESTAPI-SEARCHES
If it helps, I'm trying to query an on-premise installation of Artifactory.
More fields can be added to the AQL using the "include" element.
For example - to list all artifacts under "libs-release-local" repository, including their module names, run the following query:
items.find(
{
"repo":{"$eq":"libs-release-local"}
}
).include("artifact.module")
Response example:
{
"results": [
{
"repo": "libs-release-local",
"path": "org/jfrog/test/multi2/2.17.0",
"name": "multi2-2.17.0.jar",
"type": "file",
"size": 1022,
"created": "2021-09-11T13:51:33.878Z",
"created_by": "deployer",
"modified": "2021-09-11T13:51:33.631Z",
"modified_by": "deployer",
"updated": "2021-09-11T13:51:33.881Z",
"artifacts": [
{
"modules": [
{
"module.name": "org.jfrog.test:multi2:2.17.0"
}
]
}
]
}
]
}
You can find all of the required information under AQL documentation.

How to compare two jsonPath values in MockMvc

I am writing tests for my spring application using MockMvc. Assume that my json result will have the following format:
{
"available": true,
"location": [
{"ID": 1, "path": "local1"},
{"ID": 2, "path": "local2"},
{"ID": 3, "path": "local3"}
],
"firstItem": "local1"
}
And I would like to test that if the value of the $.firstItem property will equal to the $.location[0].path or not, actually they are should be equal. Which expectation should I put in the third expect below?
mockMvc.perform(get(url))
.andExpect(jsonPath("$.available", equalTo(true)))
.andExpect(jsonPath("$.location", hasSize(3)))
.andExpect(jsonPath("$.firstItem", ????));
Thank you very much for your help!
I'm newbie in this area, but this works for me:
mockMvc.perform(get(url))
.andDo(mvcResult -> {
String json = mvcResult.getResponse().getContentAsString();
String a = JsonPath.parse(json).read("$.firstItem").toString();
String b = JsonPath.parse(json).read("$.location[0].path").toString();
Assert.isTrue(a.equals(b),"firstItem is different from location[0].path");
});

Query in a key-value list field DynamoDB

I'm attempting make a query in a field that is list of key-value, as below.
Unfortunatelly I'm novice in DynamoDB, sorry.
My goal is get a record using a filter like:
Where
TransactionParameterList.Name = "HOSTING_NR" and
TransactionParameterList.OPERATION = "1234"
It's possible?
How?
I'm using AWS .NET SDK
Regards!
"TransactionID": "657",
"TransactionInstanceIdentifier": "919C5A0E-8786-4B86-87BF-5080E2639406",
"TransactionParameterList": [
{
"Name": "HOSTING_NR",
"Value": "1234"
},
{
"Name": "OPERATION",
"Value": "GetData"
}
],
"TransactionStepID": "1491",
"TransactionStepInstanceIdentifier": "0B0763AB-A847-479D-8EFE-43B842F2B2EB"
}
As of now DynamoDB does not support querying list of map items.
workaround in discussion forum here

/film/film/runtime always returns null

Whenever I try to query for the length of a film I get lists of null. The query I use is directly from the "Build query" button on their site and looks like this:
[{
"id": null,
"name": null,
"type": "/film/film",
"/film/film/runtime": []
}]
Ufortunately all the responses I get look like this:
{
"name": "4D Man",
"type": "/film/film",
"/film/film/runtime": [
null
],
"id": "/en/4d_man"
}
I can hover over the links you can see on the query page and see the runtime (in this case 85 minutes) but as you can see all I get from the query is null. This may be a Freebase bug, but any help is appreciated. Thank you.
There's not a single runtime of a film, the same film can have different runtimes (original version, director's cut, etc...) Freebase use the film_cut type to contain the different runtimes of a movie
You can use this query to get the runtimes:
[{
"id": null,
"name": null,
"/film/film/runtime": [{
"runtime": null
}]
}]
Tune this query to your needs, you may need type_of_film_cut or film_release_region.

Resources