my project backend is arangodb. I have two collections named "test" and "demo". i need to fetch data from both these tables. my data is like this:
test
[
{
"firstName": "abc",
"lastName": "pqr",
"company": "abc Industries",
"id": "1234"
},
{
"firstName": "xyz",
"lastName": "qwe",
"company": "xyz Industries",
"id": "5678"
}
]
demo
[
{
"clientId": "1234",
"subject": "test",
"message": "testing",
"priority": "High",
"status": "closed",
"id": "111111"
},
{
"clientId": "1234",
"subject": "hiii",
"message": "demo",
"priority": "High",
"status": "closed",
"id": "222222"
},
]
in this id of the test is same as clientid of the demo. i need to select data from the table that is data of the client "1234". how can i implement this using AQL(arango query language). i am new to arango. any suggestion will highly appreciable.
You can do this with joins or subqueries.
A solution with a subqueries would look like:
FOR t IN test
FILTER t.id == #client
RETURN {
test: t,
demo: (FOR d IN demo
FILTER d.clientId == #client
RETURN d)
}
The #client is a bind parameter which contains your value 1234.
The result is:
[
{
"test": {
"_key": "140306",
"_id": "test/140306",
"_rev": "_Urbgapq---",
"company": "abc Industries",
"firstName": "abc",
"id": "1234",
"lastName": "pqr"
},
"demo": [
{
"_key": "140233",
"_id": "demo/140233",
"_rev": "_UrbfyAm---",
"clientId": "1234",
"id": "222222",
"message": "demo",
"priority": "High",
"status": "closed",
"subject": "hiii"
},
{
"_key": "140200",
"_id": "demo/140200",
"_rev": "_UrbfjfG---",
"clientId": "1234",
"id": "111111",
"message": "testing",
"priority": "High",
"status": "closed",
"subject": "test"
}
]
}
]
For t in test
for d in demo
filter t.id == d.clientId
filter t.id == #client
return {t,d}
FOR collection IN [test,demo]
FOR x IN collection
RETURN x
Related
I have the following result set from the database, The result is an array of objects but I want it to look alike a nested objects as shown in the example.
[
{
"id": 4,
"entity": "dashboard",
"key": "message",
"value": "How to watch Netflix with XXX on Android?",
"locale": "en",
"created_at": "2022-10-25T14:41:38.000+05:00",
"updated_at": "2022-10-25T14:41:38.000+05:00"
},
{
"id": 9,
"entity": "in_survey",
"key": "content",
"value": "",
"locale": "en",
"created_at": "2022-10-25T14:41:38.000+05:00",
"updated_at": "2022-10-25T14:41:38.000+05:00"
}
]
Need a response like this from the above JSON
{
"dashboard": {
"message": "How to watch XYZ on Android?",
},
"in_survey": {
"content": ""
}
}
How do i a write a query that will copy the phoneNumber from data.accounts.contact.phone.phoneNumber to data.phoneNumber in jsonb postgres.
I tried this command
UPDATE customer."user" SET domain = jsonb_set(domain,'{phoneNumber}', text('domain' ->'accounts'-> 0 -> 'contacts' -> 'phone' -> 'phoneNumber'))
but got this error
Error: HINT: Could not choose a best candidate operator. You might need to add explicit type casts.
SQL state: 42725
Character: 1913
{
"id": "87b31b1f-5dae-4506-8099-9812fa1633eb",
"gender": "F",
"status": "VERIFIED",
"lastName": "Lawal",
"password": "T3m1t0p3",
"username": "aminat2#gmail.com",
"firstName": "Aminat",
"phoneNumber": "",
"accounts": [
{
"status": "IN_REVIEW",
"contact": {
"phone": { "phoneNumber": "7809284029", "diallingCode": "+44" },
"address": { "city": "London", "address": "42 Sark Walk", "country": "United Kingdom", "postcode": "E163PS" },
"emailAddress": "aminat2#gmail.com"
},
"location": {
"id": "4a110b1f-9319-4282-b645-81ea71b53e04",
"status": "ACTIVE",
"currency": {
"id": "1",
"to": false,
"date": "2021-09-19T16:45:33",
"from": true,
"buyFxRate": "1",
"sellFxRate": "1",
"
},
"diallingCode": "+44",
"locationLabel": "United Kingdom",
"
"modifiedDateTime": "2021-09-19T16:45:33",
},
}
],
}
Given the following collection data in a CosmosDB database:
[
{
"id": "1",
"title": "Blog post #1",
"tags": ["tag1", "tag2", "tag3"]
},
{
"id": "2",
"title": "Blog post #2",
"tags": ["tag1"]
}
]
How would you flatten this into a result set that looks like the following:
[
{
"id": "1",
"title": "Blog post #1",
"tagName": "tag1"
},
{
"id": "1",
"title": "Blog post #1",
"tagName": "tag2"
},
{
"id": "1",
"title": "Blog post #1",
"tagName": "tag3"
},
{
"id": "2",
"title": "Blog post #2",
"tagName": "tag1"
}
]
The ultimate goal in this example is finding the tag count, so this query would be wrapped in something like SELECT COUNT(1) as count, s.tagName FROM (subquery) s GROUP BY s.tagName.
You got the right idea but are using the wrong type of join. You need to use JOIN IN to flatten the array.
SELECT c.id, c.title, t AS tagName
FROM c
JOIN t IN c.tags
how to make this data to asc order by user's first name and user's last name.
I got the response, want to sort the records by user's first name but it is taking from creation date I guess when using sort how can I make it base on user's first name and user's last name please guide
{
"response": {
"items": [
{
"_id": "5e71f86bd300b313df52fb2f",
"last_message": {
"text": "Alex",
"users": [
{
"_id": "5e4a8d2d3952132a08ae5764",
"first_name": "zack",
"last_name": "Write"
}
]
},
"texter": [
"alex",
"$0ctg"
],
"title": "New group1",
"group": true,
"members": [
{
"_id": "5e4a8afc3952132a08ae575e",
"first_name": "test3",
"last_name": "test4"
}
],
"managers": [
"5e4a8afc3952132a08ae575e"
],
"member": {
"_id": "5e4a8afc3952132a08ae575e",
"first_name": "test3",
"last_name": "test4"
}
},
{
"_id": "5e4e740f380054797d9db621",
"last_message": {
"text": "",
"users": [
{
"_id": "5e4a8d2d3952132a08ae5764",
"first_name": "yuhan",
"last_name": "jacob"
}
]
},
"texter": [
"",
"",
"",
"",
"",
"new iphone x\n brand new iphone wv wwvqzwzvq had sqswgscq wow you wholeheartedly q \n $600.00",
"helo",
"hello",
"hi"
],
"members": [
{
"_id": "5e4d0973babf2b74ca868f4d",
"first_name": "alex",
"last_name": "hales"
}
],
"managers": [],
"member": {
"_id": "5e4d0973babf2b74ca868f4d",
"first_name": "alex",
"last_name": "hales"
}
}
]
}
}
Tried
{
$sort: {
users: 1,
}
},
doesn't help much
Also if I would like to add two field asc desc order what would be the process in MongoDB
Try this hope this will help you !
{
$sort: { "users.first_name": 1 }
},
The response i am getting is below Which i need to convert the input JSON Format to other JSON structure and send the response back. I am struck how to get the data from the JSOn and construct the new JSON format
{
"totalSize": 1,
"done": true,
"records": [{
"attributes": {
"type": "test123",
"url": "/services/data/testapp"
},
"Id": "8373837",
"Name": "6294",
"Application": "9932932932",
"contact": {
"attributes": {
"type": "testcon",
"url": "/services/data/testappsss"
},
"Name": "testName",
"FirstName": "test",
"LastName": "name",
"MailingStreet": null,
"MailingCity": null,
"unemail": "testname#test,.co",
"MailingState": null,
"MailingCountry": null,
"MailingPostalCode": null,
"stuId": "328237832"
},
"currentusbss": "83277832873278",
"currentsu": {
"attributes": {
"type": "testsub",
"url": "/services/data/v44.0jsjsj"
},
"price": 2,
"Name": "SUB-20426"
},
"bal": 234,
"startdate": "2020-02-03",
"enddate": "2020-05-03"
}]
}
I need to convert above JSON format to below JSON format and send it using set-body method in out-bond policies
{
"info": {
"studentName": "testName",
"studentFirstName": "test",
"studentMiddleName": "",
"studentLastName": "Name",
"studentEmail": "testname#test,.co",
"role": "STUDENT",
"billingCountryCode": "US",
"systemId": "XX",
"stuId": "328237832"
},
"address": {
"address1": "1234 Grove St",
"address2": "",
"city": "Tempe",
"countryCode": "US",
"countryDescription": "UNITED STATES",
"stateCode": "AZ",
"stateDescription": "Arizona",
"postalCode": "45235",
"foreignState": "Arizona",
"region": "Domestic",
"phoneNumber": ""
},
"account": {
"institutionId": "1",
"paymentPlan": "N",
"currencyDesc": "United States Dollars",
"currencyType": "USD",
"bal": 234,
"daysLate":"18",
"opportunityId": "9932932932",
"studentParameterName": null,
"studentParameterValue": null
},
"studentTerms": [
{
"startdate": "2020-02-03",
"enddate": "2020-05-03",
"Name": "SUB-20426",
"description": "XQYember 03, 2020 "
}
]
}
You can use Liquid Template for this case:
Using Liquid Templates in Azure API Management
Using Liquid templates with set body
Or you create a new body in the outbound-section with a new JObject