I have a JSON column (called "roi") which contains users' Instagram performance. This is the roi column:
{
"data": {
"campaignName": "Master Cosy",
"currency": "GBP",
"reportData": {
"AAAAAAAAAA": {
"id": "0f20d833-d0f-bdb7-19",
"name": "cornish_gregorys",
"thumbnail": "https://sstagram.com/v/t51.2885-19/s320x320/87244862_1017848048596",
"Name": "cornisorys",
"instagramCount": 2319,
"instagramEngagementFactor": 0,
"instagramAuthorised": true,
"hasPosts": true,
"budget": 0,
"derivedFee": 0,
"inventoryItems": [],
"trackedAssetsStats": {
"totalAssets": 9,
"facebook": {
"count": 0
},
"instagram": {
"total": 9,
"stories": 9,
"carousels": 0,
"videos": 0,
"images": 0,
"igtvs": 0
},
"BBBBBBBBBBBBB": {
"id": "d3d30db4-0b453dfc3ae2a09",
"name": "itssdha",
"thumbnail": "https://in9809609728_n.jpg?_nc_ht=instagram.fhel5-1.fna.fbcdn.net&_nc_ohc=Se3ySAoqnFwAX4f6&oeF1623",
"Name": "itsshdha",
"instagramCount": 26700,
"instagramEngagementFactor": 0,
"instagramAuthorised": true,
"hasPosts": true,
"budget": 0,
"derivedFee": 0,
"inventoryItems": [],
"trackedAssetsStats": {
"totalAssets": 5,
"facebook": {
"count": 0
},
"instagram": {
"total": 9,
"stories": 9,
"carousels": 0,
"videos": 0,
"images": 0,
"igtvs": 0}, etc.....
After "reportData" I have the specific names of the users (in this case AAAAAAAA and BBBBBBBBB) and within them the performance of their Instagram accounts. How can I access all the metrics within the object username without having to type the specific username (AAAAAAAA and BBBBBBBBB)
My query is this:
roi -> 'date' -> 'reportData' -> 'AAAAAAA' -> 'instagramCount' -> etc ....
But I need something to 'jump' this part -> 'AAAAAAA' -> and go straight to the metrics, in this case 'instagramCount', etc...
From what I have read I may need to use jsonb_each, does anyone know how to use it?
demos:db<>fiddle
You have several ways.
Use jsonb_each() to expand all users' data: You can create a record per user and than ask for the count afterwards
SELECT
users.value -> 'instagramCount'
FROM
mytable,
jsonb_each(mydata -> 'data' -> 'reportData') as users
Since Postgres 12 you can use JSONpath for that, to achieve the same:
SELECT
jsonb_path_query(mydata, '$.**.instagramCount')
FROM mytable
Related
I am new to feathersjs and I've breaking my head on how to restrict users from viewing other's data. For instance from postman when you do find/get(id) http://localhost/users you see list of all the users that are currently registered. However I would only like to return the current users data.
From:
{
"total": 2,
"limit": 10,
"skip": 0,
"data": [
{
"id": 1,
"email": "test#feathersjs.com",
"auth0Id": null,
"createdAt": "2020-02-01T23:16:30.833Z",
"updatedAt": "2020-02-01T23:16:30.833Z"
},
{
"id": 2,
"email": "test1#feathersjs.com",
"auth0Id": null,
"createdAt": "2020-02-01T23:31:50.904Z",
"updatedAt": "2020-02-01T23:31:50.904Z"
}
]
}
To:
{
"total": 1,
"limit": 10,
"skip": 0,
"data": [
{
"id": 1,
"email": "test#feathersjs.com",
"auth0Id": null,
"createdAt": "2020-02-01T23:16:30.833Z",
"updatedAt": "2020-02-01T23:16:30.833Z"
},
]
}
How do I filter result in the after hook function? Can someone please explain.
Answer:
Missed a basic step. All the find(), update() etc return result based on parent class. By Customizing find() method in your own class and using Sequlize.findOne({}) you can return the result you desire.
Damn! I was stupid to not read the docs fully.
I have a JSON list with 253 entries and 7 records where the 7th record is a list with usually 2 entries.
I'm trying to convert this in Power Query to give me a table output. I've only really ever used the basic connection in Excel to do this automatically without problems.
My current error is:
Expression.Error: We cannot convert a value of type Record to type Text.
Details:
Value=Record
Type=Type
I'm not sure where to go and I can't see examples for my specific situation, although I'm sure there are plenty of examples - just that I'm not good enough with this to understans
[
{
"Id": "lorum-ipsum1",
"Description": "sitename 1",
"Latitude": 1.0,
"Longitude": -1.0,
"Postcode": "AB1 2CD",
"CountryCode": "GB",
"Connectors": [
{
"Id": "lorum-ipsum1-a",
"Number": 1,
"Status": 1,
"ErrorCode": "NoError",
"ChargepointName": "GP00000",
"Shape": 0,
"Mode": 0,
"Volts": 240,
"Amps": 0,
"Phase": 2,
"PricingInformationUrl": "hrefhere",
"UsageRestrictions": []
},
{
"Id": "lorum-ipsum1-b",
"Number": 2,
"Status": 1,
"ErrorCode": "NoError",
"ChargepointName": "GP0000",
"Shape": 0,
"Mode": 0,
"Volts": 240,
"Amps": 0,
"Phase": 2,
"PricingInformationUrl": "hrefhere",
"UsageRestrictions": []
}
]
},
{
"Id": "lorum-ipsum2",
"Description": "sitename 2",
"Latitude": 1.0,
"Longitude": -1.0,
"Postcode": "AB1 2CD",
"CountryCode": "GB",
"Connectors": [
{
"Id": "lorum-ipsum2-a",
"Number": 1,
"Status": 1,
"ErrorCode": "NoError",
"ChargepointName": "GP00000",
"Shape": 0,
"Mode": 0,
"Volts": 240,
"Amps": 0,
"Phase": 2,
"PricingInformationUrl": "hrefhere",
"UsageRestrictions": []
},
{
"Id": "lorum-ipsum2-b",
"Number": 2,
"Status": 1,
"ErrorCode": "NoError",
"ChargepointName": "GP0000",
"Shape": 0,
"Mode": 0,
"Volts": 240,
"Amps": 0,
"Phase": 2,
"PricingInformationUrl": "hrefhere",
"UsageRestrictions": []
}
]
},
I think you want to use Table.FromRecords function to transform the JSON into a table. However, since the Connectors field of each record is itself a list of records, I think you will need to call it a second time.
To give you an example:
let
serialised = "[{""Id"":""lorum-ipsum1"",""Description"":""sitename 1"",""Latitude"":1,""Longitude"":-1,""Postcode"":""AB1 2CD"",""CountryCode"":""GB"",""Connectors"":[{""Id"":""lorum-ipsum1-a"",""Number"":1,""Status"":1,""ErrorCode"":""NoError"",""ChargepointName"":""GP00000"",""Shape"":0,""Mode"":0,""Volts"":240,""Amps"":0,""Phase"":2,""PricingInformationUrl"":""hrefhere"",""UsageRestrictions"":[]},{""Id"":""lorum-ipsum1-b"",""Number"":2,""Status"":1,""ErrorCode"":""NoError"",""ChargepointName"":""GP0000"",""Shape"":0,""Mode"":0,""Volts"":240,""Amps"":0,""Phase"":2,""PricingInformationUrl"":""hrefhere"",""UsageRestrictions"":[]}]},{""Id"":""lorum-ipsum2"",""Description"":""sitename 2"",""Latitude"":1,""Longitude"":-1,""Postcode"":""AB1 2CD"",""CountryCode"":""GB"",""Connectors"":[{""Id"":""lorum-ipsum2-a"",""Number"":1,""Status"":1,""ErrorCode"":""NoError"",""ChargepointName"":""GP00000"",""Shape"":0,""Mode"":0,""Volts"":240,""Amps"":0,""Phase"":2,""PricingInformationUrl"":""hrefhere"",""UsageRestrictions"":[]},{""Id"":""lorum-ipsum2-b"",""Number"":2,""Status"":1,""ErrorCode"":""NoError"",""ChargepointName"":""GP0000"",""Shape"":0,""Mode"":0,""Volts"":240,""Amps"":0,""Phase"":2,""PricingInformationUrl"":""hrefhere"",""UsageRestrictions"":[]}]}]",
deserialised = Json.Document(serialised),
toTable = Table.FromRecords(deserialised),
transformConnectors = Table.TransformColumns(toTable, {{"Connectors", Table.FromRecords}})
in
transformConnectors
which gives me:
From there, you can explore/continue the rest of the transformation yourself (since you haven't specified what you want).
You can expand some/all nested columns inside of the Connectors column by either clicking the icon highlighted in the image above -- or writing any necessary M code.
How do I approach writing a query to return all the records matching both match.id and player.name for the following collection?
{
"match": {
"id": 1,
"event": {
"timestamp": "2015-06-03 15:02:22",
"event": "round_stats",
"round": 1,
"player": {
"name": "Jim",
"userId": 45,
"uniqueId": "BOT",
"team": 2
},
"shots": 0,
"hits": 0,
"kills": 0,
"headshots": 0,
"tks": 0,
"damage": 0,
"assists": 0,
"assists_tk": 0,
"deaths": 0,
"head": 0,
"chest": 0,
"stomach": 0,
"leftArm": 0,
"rightArm": 0,
"leftLeg": 0,
"rightLeg": 0,
"generic": 0
}
}
}
I've attempted it with both the following query statements, but had no luck -- they both return no results:
db.warmod_events.find( { $and: [ { "match.id": 1}, { "player.name": 'Jim' } ] } )
db.warmod_events.find( { $and: [ { "match.id": 1}, { "event": { "player.name": "Jim" } } ] } )
I'm pretty new to Mongo and any guidance and explanation would help a bunch -- truthfully I've chosen to use Mongo for this project as the data I am working with is already presented in this form (the JSON) and, due to that, it seemed like a good opportunity to use and learn Mongo.
I am referring to the documentation on the Mongo site currently.
Thanks all
Try the following query:
db.warmod_events.find({ "match.id": 1, "match.event.player.name": 'Jim' })
which will match documents where the match id is the same as the embedded document player name.
So this must be a strange question, I want sails.js ORM to search something like following
If this is the result for query for the following
Venue.findOne({id: 125274827508536}).exec()
returns >
{
"id": "125274827508536",
"attire": "Casual",
"can_post": false,
"category": "Restaurant/cafe",
"category_list": [
{
"id": "200742186618963",
"name": "Vegetarian & Vegan Restaurant"
},
{
"id": "192108214153222",
"name": "Breakfast & Brunch Restaurant"
},
{
"id": "188296324525457",
"name": "Sandwich Shop"
}
],
"checkins": 562,
"cover": {
"cover_id": 356427064393310,
"offset_x": 0,
"offset_y": 13,
"source": "https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-xaf1/t31.0-8/s720x720/460144_356427064393310_1179113344_o.jpg",
"id": "356427064393310"
},
"culinary_team": "Ramy Abu-Yousef : Owner, Chef\nDallas Jones: Chef",
"description": "Unique Sandwiches\nDelicious Salads\nHomemade Soups (4 daily)\nFresh Fruit Smoothies\nMilkshakes\nMOUSTACHE WALL OF FAME",
"general_manager": "Ramy Abu-Yousef & Syndey Friedemann",
"has_added_app": false,
"hours": {
"mon_1_open": "08:00",
"mon_1_close": "22:00",
"tue_1_open": "08:00",
"tue_1_close": "22:00",
"wed_1_open": "08:00",
"wed_1_close": "22:00",
"thu_1_open": "08:00",
"thu_1_close": "22:00",
"fri_1_open": "08:00",
"fri_1_close": "22:00",
"sat_1_open": "08:00",
"sat_1_close": "22:00",
"sun_1_open": "08:00",
"sun_1_close": "22:00"
},
"is_community_page": false,
"is_published": true,
"likes": 540,
"link": "https://www.facebook.com/JohnnyBarrs",
"location": {
"city": "Queenstown",
"country": "New Zealand",
"latitude": -45.032691433795,
"longitude": 168.66154298959,
"street": "15 Church Street",
"zip": "9300"
},
"name": "Johnny Barr's",
"parking": {
"lot": 1,
"street": 1,
"valet": 0
},
"payment_options": {
"amex": 1,
"cash_only": 0,
"discover": 0,
"mastercard": 1,
"visa": 1
},
"phone": "+64 (0)3 409 0169",
"price_range": "$$ (10-30)",
"restaurant_services": {
"delivery": 1,
"catering": 0,
"groups": 1,
"kids": 1,
"outdoor": 0,
"reserve": 0,
"takeout": 1,
"waiter": 0,
"walkins": 1
},
"restaurant_specialties": {
"breakfast": 1,
"coffee": 1,
"dinner": 1,
"drinks": 1,
"lunch": 1
},
"talking_about_count": 2,
"username": "JohnnyBarrs",
"website": "www.johnnybarrs.com",
"were_here_count": 562
}
Now what I need sails to do is the following
Venue.findOne({'restaurant_services': {'delivery': 1}).exec()
To return the same object as I have shown above,
Any thoughts please ?
If your adapter is mongo then you can do this out of the box
Venue.findOne({'restaurant_services.delivery': 1}).exec()
So you should consider your options if you can transform the data into another source to preform this query.
If not and your adapter is SQL based then it is more difficult and would require more information on your use case to decide on the most efficient option.
For instance if you could limit your query to a few indexed fields in a SQL database, you could then use lodash to find your records within your records.
Venue.find({/*limiting criteria to bring down the number of results*/}).exec(function(err,results){/* JSON.parse(results) then use lodash to find the final result*/})
Another option could be
Venue.find({restaurant_services: {contains: 'delivery: 1'}}).exec()
that is an out of the box idea, but one that might work.
Again depends deeply on your setup, how its indexed and out of how many venues that one would need to be found.
I deleted an item you do not need to solr, but I solr response still appears.
The json:
{
"responseHeader": {
"status": 0,
"QTime": 1,
"params": {
"facet": "true",
"q": "*:*",
"facet.limit": "-1",
"facet.field": "manufacturer",
"wt": "json",
"rows": "0"
}
},
"response": {
"numFound": 84,
"start": 0,
"docs": []
},
"facet_counts": {
"facet_queries": {},
"facet_fields": {
"manufacturer": [
"Chevrolet",
0,
"abarth",
1,
"audi",
7,
"austin",
1,
"bmw",
2,
"daewoo",
2,
"ford",
1,
"fso",
1,
"honda",
1,
"hyundai",
1,
"jaguar",
3,
"lexus",
1,
"mazda",
1,
"mitsubishi",
1,
"nissan",
1,
"pontiac",
1,
"seat",
1
]
},
"facet_dates": {},
"facet_ranges": {}
}
}
the deleted item is "chevrolet", now this to '0 'but it still appears.
"manufacturer":["Chevrolet",0,
I wish I could delete the item completely, is that possible.. Thanks.
Here is a two step approach I would follow:
Make sure changes(deletion) is committed. You may issue a commit
If it still shows facets with zero count, you may append &facet.mincount=1 to your query
&facet.mincount=1 will make sure facets with zero count do not show up.
For more details, please refer to: http://wiki.apache.org/solr/SimpleFacetParameters#facet.mincount
In your case probably it is because of uninverted index created by solr.
Pass facet.mincount=1 in your query to get rid of this problem.