Through a XMLImport function in Excel I retrieve a JSON set of data. I would like to retrieve a list of ONLY all the names of the pools (in Example below, only 'Men Singles A' and 'Men Singles B').
Because the array of data has different properties called /name I do not know a way to filter out all the /name properties that are part of the /teams property.
[
{
"poolId": 864,
"position": 0,
"name": "Men Singles A",
"totTeams": 7,
"nrPlayersInTeam": 1,
"teams": {
"6453": {
"id": 6453,
"name": "Peter",
{
"id": 3886,
"name": "Peter",
}
]
},
"6501": {
"id": 6501,
"name": "Jack",
"players": [
{
"id": 3912,
"name": "Jack",
}
]
},
}
},
{
"poolId": 865,
"position": 1,
"name": "Men Singles B",
"totTeams": 22,
"nrPlayersInTeam": 1,
"teams": {
"6406": {
"id": 6406,
"name": "John",
"players": [
{
"id": 3844,
"name": "John",
}
]
},
"6408": {
"id": 6408,
"name": "Matthew",
"players": [
{
"id": 3845,
"name": "Matthew",
}
]
},
}
}
]
When trying the following ImportXML function with a Xpath selection, I get a list of all the /name/ properties found in the JSON array.
=IMPORTXML("https://www.tournia.net/api/v2/test/pools?tournamentUrl=test&_format=xml";"//name")
Retrieved List:
Men Singles A
Peter
Peter
Jack
Jack
Men Singles B
John
John
Mtthew
Matthew
What would be the appropriate XPath code to only get a list of all the pool names?
Related
my data structure is and products elements all tags in empty
I need to add a value to mongo db inner object with array element without looking at other value. Can some one advice to do this.
[
{
"item": "journal",
"id": 11,
"products": [
{
"id": 3,
"name": "p one",
"tags": []
}
]
},
{
"item": "notebook",
"id": 14,
"products": [
{
"id": 4010,
"name": "item-five",
"tags": []
}
]
}
]
and I want to add tag in products elements with match product id '4010', so the expected response should be like
[
{
"item": "journal",
"id": 11,
"products": [
{
"id": 3,
"name": "p one",
"tags": []
}
]
},
{
"item": "notebook",
"id": 14,
"products": [
{
"id": 4010,
"name": "item-five",
"tags": [
{
"id": 21,
"key": "tag-one",
"name": "tag-one",
}
]
}
]
}
]
You should look at arrayFilter option https://www.mongodb.com/docs/v6.0/reference/operator/update/positional-filtered/#update-all-documents-that-match-arrayfilters-in-an-array
Something like this might do the trick.
db.collection.updateMany(
{ },
{ $push: { "products.$[x].tags": {
"id": 21,
"key": "tag-one",
"name": "tag-one",
} } },
{ arrayFilters: [{ "x.id": 4010 }] }
);
Is it Possible to show specific data in spinner from a List. Here I stuck with the concept. can anyone elaborate me if I can do it or not.
{
"status": "OK",
"message": "Sucess",
"result": [
{
"id": 2,
"name": "DHAKA",
"countryId": "001"
},
{
"id": 4,
"name": "RAJSHAHI",
"countryId": "001"
},
{
"id": 11,
"name": "RANGPUR",
"countryId": "001"
},
{
"id": 6,
"name": "SYLHET",
"countryId": "001"
}
]
}
Here Is my data. I Don't want to show whole list. I just need to know that how will be my approach.
Currently I have a many-to-many relationship between entities. A Transaction contains many persons and a Person contains many Transactions. I'm writing a query to filter out transactions so that the transactions contains the person's name. The problem I'm running into is when I filter based on name, it removes the other Person from the transaction.
Example:
{
"id": 1,
"txnDate": "2021-03-09T12:40:26.000Z",
"persons": [
{
"id": 1,
"name": "Bill"
},
{
"id": 2,
"name": "Jen"
}
]
},
{
"id": 2,
"txnDate": "2021-03-09T12:40:26.000Z",
"persons": [
{
"id": 2,
"name": "Jen"
},
{
"id": 3,
"name": "Bob"
}
]
},
My current query is:
query.leftJoinAndSelect('transaction.persons', 'persons')
.andWhere('persons.name = :name', { name });
where name is a string. If I set name= Bill it results in:
{
"id": 1,
"txnDate": "2021-03-09T12:40:26.000Z",
"persons": [
{
"id": 1,
"name": "Bill"
},
]
},
However, I want it so that when I query by name it would result in:
{
"id": 1,
"txnDate": "2021-03-09T12:40:26.000Z",
"persons": [
{
"id": 1,
"name": "Bill"
},
{
"id": 2,
"name": "Jen"
}
]
},
I'm really stuck and I would love any ideas on how to solve this
Current Stack: Nodejs, TypeORM, TypeScript
I am trying to return the value of "description" in "dependentPreferences" where the response meets two conditions: First, check if the name is "John Smith" and then check if the "image" in preferences equals to "papaya.jpg".
The response body is as follows:
[
{
"id": 1,
"name": "John Smith",
"description": null,
"shortDescription": "No recorded interests.",
"alias": "JS",
"preferences": [
{
"id": 1,
"description": "likes candy and papaya",
"image": "papaya.jpg",
"name": "Papaya",
"dependentPreferences": [
{
"id": 1,
"description": "Fruit must be ripe",
"image": "ripe-papaya.jpg",
"name": "pap"
}
]
}
]
},
{
"id": 2,
"name": "Jane Smith",
"description": null,
"shortDescription": "No recorded interests.",
"alias": "JS",
"preferences": [
{
"id": 1,
"description": "likes candy and papaya",
"image": "papaya.jpg",
"name": "Papaya",
"dependentPreferences": [
{
"id": 1,
"description": "Candy must be Skittles",
"image": "Skittles.jpg",
"name": "skt"
}
]
}
]
}
]
So far, i have tried something like this:
response.jsonPath().getString("find { it.name == 'John Smith' }.preferences.find {it.image == 'papaya.jpg'}.dependentPreferences.description
but it is complaining about the syntax. I know this portion of the code works to find the image:
response.jsonPath().getString("find { it.name == 'John Smith' }.preferences.image
but i am having trouble constructing the second condition. Any help would be appreciated.
Working example here. This works for me:
def endpoint = "http://localhost:3130/ids.json"
def jsonResponse = get(endpoint).then().contentType(ContentType.JSON).extract().response()
def path = jsonResponse.jsonPath()
def result = path.getString("find { it.name == 'John Smith' }.preferences.find {it.image == 'papaya.jpg'}.dependentPreferences.description")
Though to be honest: in the JSON, dependentPreferences is an array of objects, so there is a chance for error if the data is different than presented.
Here i like to explain my problem.
How can i write a mongoose query to retrieve every subdocument from JSON without passing parent_id.
[
{
"_id": "56a320003fe17cc7363dd0d7",
"name": "Leanna Jacobson",
"gender": "female",
"friends": [
{
"id": 0,
"name": "Riley Case"
},
{
"id": 1,
"name": "Herman Carter"
},
{
"id": 2,
"name": "Pacheco Woodard"
}
]
},
{
"_id": "56a3200001501cfa1ea2641d",
"name": "Juliana Bonner",
"gender": "female",
"friends": [
{
"id": 0,
"name": "Keller Woodward"
},
{
"id": 1,
"name": "Fern Knight"
},
{
"id": 2,
"name": "Cain Richards"
}
]
},
{
"_id": "56a3200006864c78ecb1aeed",
"name": "Gena Stark",
"gender": "female",
"friends": [
{
"id": 0,
"name": "Kate Franco"
},
{
"id": 1,
"name": "Araceli Mcclure"
},
{
"id": 2,
"name": "Molly Nelson"
}
]
},
{
"_id": "56a320006d868155161038b6",
"name": "Eve Gonzalez",
"gender": "female",
"friends": [
{
"id": 0,
"name": "Pam Lang"
},
{
"id": 1,
"name": "Christy Marks"
},
{
"id": 2,
"name": "Donovan Warren"
}
]
},
{
"_id": "56a3200066b94852f5680568",
"name": "Coleman Wooten",
"gender": "male",
"friends": [
{
"id": 0,
"name": "Roberta Olson"
},
{
"id": 1,
"name": "Roseann Reid"
},
{
"id": 2,
"name": "Kerri Russell"
}
]
}
]
Here i need to retrieve every friends details from the subdocument array friends for every parent.
so how can i write query for this?????
Suppose the name of your schema is Person, try this one.
//find all document, only select `friends` field from every document
Person.find({}, 'friends', function (err, friends) {
// the return friends is the [[friends], [friends], ...]
});