Export data by following JSON Schema - mongodb

I have many fields on my MongoDB, but I want to export only these out which appear on my JSON Schema.
This is my JSON schema, I want these fields to .CSV:
{
"names": [
{
"source": 0,
"order": 0,
"version": 0,
"registrationDate": "",
"endDate": "",
"name": "",
"language": ""
}
],
"auxiliaryNames": [
{
"source": 0,
"order": 0,
"version": 0,
"registrationDate": "",
"endDate": "",
"name": "",
"language": ""
}
],
"addresses": [
{
"source": 0,
"version": 0,
"registrationDate": "",
"endDate": "",
"careOf": "",
"street": "",
"postCode": "",
"city": "",
"language": "",
"type": 0,
"country": ""
}
]

Related

KODI JSONRPC Player.GetItem method provide empty details

I start a new video with JSON-RPC call:
{"jsonrpc": "2.0",
"method": "Player.Open",
"params":
{"item":
{"file": "c:\\MyCodes\\samples\\sample-6s.mp4" }},
"id": 1
}
Video started and I want to get the video details and use the following Player.GetItem method:
{
"jsonrpc": "2.0",
"method": "Player.GetItem",
"params": {
"properties": [
"title",
"album",
"artist",
"season",
"episode",
"duration",
"showtitle",
"tvshowid",
"thumbnail",
"file",
"fanart",
"streamdetails"
],
"playerid": 1
},
"id": "VideoGetItem"
}
The problem I got back this:
{
"id": "VideoGetItem",
"jsonrpc": "2.0",
"result": {
"item": {
"album": "",
"artist": [],
"episode": -1,
"fanart": "",
"file": "c:\\MyCodes\\samples\\sample-6s.mp4",
"label": "sample-6s.mp4",
"season": -1,
"showtitle": "",
"streamdetails": {
"audio": [],
"subtitle": [],
"video": []
},
"thumbnail": "",
"title": "",
"tvshowid": -1,
"type": "unknown"
}
}
}
but if I start the same video from KODI GUI I got back this:
{
"id": "VideoGetItem",
"jsonrpc": "2.0",
"result": {
"item": {
"album": "",
"artist": [],
"episode": -1,
"fanart": "",
"file": "C:\\MyCodes\\samples\\sample-6s.mp4",
"label": "sample-6s.mp4",
"season": -1,
"showtitle": "",
"streamdetails": {
"audio": [
{
"channels": 2,
"codec": "mp3",
"language": ""
}
],
"subtitle": [],
"video": [
{
"aspect": 1.3333330154418946,
"codec": "mpeg4",
"duration": 2701,
"hdrtype": "",
"height": 384,
"language": "",
"stereomode": "",
"width": 512
}
]
},
"thumbnail": "image://video#C%3a%5cMyCodes%5csamples%5csample-6s.mp4/",
"title": "",
"tvshowid": -1,
"type": "unknown"
}
}
}
Any idea, or experience? Maybe I should use a different method to get the currently running video details?

Node red write double word

How do I convert number to double word in Node-red?
I tried throwing the array in
but no response
I'm not very good at node red, please answer me, thank you
What do you mean converting 'number' to 'double word'?
Data type 'double' is already number type.
Do you mean String to number?
[
{
"id": "bd8884d5c2f82322",
"type": "tab",
"label": "플로우 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "4546977fe7434e95",
"type": "inject",
"z": "bd8884d5c2f82322",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "1234.34",
"payloadType": "str",
"x": 160,
"y": 40,
"wires": [
[
"a93489fbd55883b2",
"f1ad7ec076bceb78"
]
]
},
{
"id": "a93489fbd55883b2",
"type": "function",
"z": "bd8884d5c2f82322",
"name": "Convert String to Number",
"func": "msg.payload=Number(msg.payload);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 370,
"y": 40,
"wires": [
[
"1f695a58ebc55f90"
]
]
},
{
"id": "1f695a58ebc55f90",
"type": "debug",
"z": "bd8884d5c2f82322",
"name": "number",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 560,
"y": 40,
"wires": []
},
{
"id": "f1ad7ec076bceb78",
"type": "debug",
"z": "bd8884d5c2f82322",
"name": "string",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 310,
"y": 80,
"wires": []
}]

Extract ? number of JSON array objects into rows

So I am trying to pivot some large Json arrays into a row by row format (postgres db). So imagine
{“searchResults”:[{“id”:“89705”,“score”:42,“title”:“Foo.”,“properties”:{…
Currently the most results we have in an array is about 300~ id's and explicitly saying;
Data::Json->'searchResults'->0->'tags'->0->>'label' as "Tag - Result 1",
...
Data::Json->'searchResults'->300->'tags'->0->>'label' as "Tag - Result
1",
Ideal Output
Array, ID , Score, Title
----
1 89705, 42, foo
1 89706, 34, bar
2 90003, 54, thing
2 98594, 53, that
(so 1,2 represent different rows in the initial table that both contain ??? amounts of objects the JSON data array)
Expanded JSON
{
"searchResults": [
{
"id": "897096",
"score": 42,
"title": "foo.",
"properties": {
"#type": "blah",
},
"publishedDate": "2018-06-30T10:20:20.555040Z",
"comments": [
{
"content": "",
"owner": {
"firstName": "",
"id": 0,
"lastName": ""
},
"id": 0,
"contentType": "",
"documentPk": 0,
"workflowStep": 0,
"order": 0
}
],
"tags": [
{
"tag": 783,
"label": "NO",
"iconClass": "",
"subGroup": "",
"exclude": false
},
{
"tag": 786,
"label": "Different name",
"iconClass": "",
"subGroup": "",
"exclude": false
}
],
"reviewTags": [
{
"tag": 2,
"label": "Accept",
"iconClass": "",
"subGroup": "",
"exclude": false
}
],
"original": {
..."names": [
{
"full_name": "This name"
}
],
"Entry Type": "Organization",
"Last Updated": "2018/05/03",
"Hit Category": "N/A",
"Aliases": [
"Olaj",
"hbhbhb"
]
},
"snippet": "",
"url": "",
"source": "_"
},
{
"id": "879057",
"score": 36,
"title": "name of company",
"properties": {
"#type": "",
"category": "SOE",
"type": "Organization",
"country": "Korea, Republic Of",
"subcategory": ""
},
"publishedDate": "2018-05-31T10:20:20.559714Z",
"comments": [
{
"content": "",
"owner": {
"firstName": "",
"id": 0,
"lastName": ""
},
"id": 0,
"contentType": "",
"documentPk": 0,
"workflowStep": 0,
"order": 0
}
],
"tags": [
{
"tag": 783,
"label": "NO",
"iconClass": "",
"subGroup": "",
"exclude": false
},
{
"tag": 786,
"label": "Different name",
"iconClass": "",
"subGroup": "",
"exclude": false
}
Any advise on what my options are here ?
Thanks #a_horse_with_no_name this worked perfectly.
it's unclear to me how the JSON continues in the array, but it seems you are looking for something like this:
with testdata(props) as (
values (
'{"searchResults":
[
{"id":"89705","score":42,"title":"Foo"},
{"id":"89706","score":34, "title":"bar"}
]}'::jsonb
)
)
select x.idx,
x.val ->> 'id' as id,
x.val ->> 'score' as score,
x.val ->> 'title' as title
from testdata, jsonb_array_elements(props -> 'searchResults') with ordinality as x (val, idx);
returns
idx | id | score | title
----+-------+-------+------
1 | 89705 | 42 | Foo
2 | 89706 | 34 | bar

How would I write a query to give me the following results?

I have 2 classes.
Activities and Comments.
Activities, is linked to comments.
Comments, has the fields username, comment and created_at
When I execute select from Activities, this is an example of my current results. Below, you will see an example of my desired results (Example 2)
Example 1
{
"#type": "d",
"#rid": "#28:38",
"#version": 10,
"#class": "Activities",
"activity_type_id": 1,
"username": "johnt",
"title": "random new activitie test",
"image": "http://www.someurl.com/images/blah-2.png",
"comments": [
"#24:26",
"#24:27",
"#24:28",
"#24:29",
"#24:30",
"#24:31"
],
"Activity_Properties": {
"comment_count": 0,
"share_count": 0,
"like_count": 0
}
}
my desired results are the following
Example 2
{
"#type": "d",
"#rid": "#28:38",
"#version": 10,
"#class": "Activities",
"activity_type_id": 1,
"username": "ultimaterandomuser",
"title": "random new activitie test",
"image": "http://www.someurl.com/images/blah.png",
"comments": [
{
"username": "randomuser1",
"comment": "randomuser1 comment"
"created_at": "2016-06-23 00:00:00",
},
{
"username": "randomuser2",
"comment": "randomuser2 comment"
"created_at": "2016-06-23 00:00:00",
},
{
"username": "randomuser3",
"comment": "randomuser3 comment"
"created_at": "2016-06-23 00:00:00",
}
],
"Activity_Properties": {
"comment_count": 0,
"share_count": 0,
"like_count": 0,
}
}
I tried your case with this simple dataset:
Output Query 1:
SELECT FROM Activities
{
"result": [
{
"#type": "d",
"#rid": "#12:0",
"#version": 1,
"#class": "Activities",
"activity_type_id": 1,
"username": "ultimaterandomuser",
"title": "random new activitie test",
"image": "http://www.someurl.com/images/blah.png",
"comments": [
"#13:0",
"#13:1",
"#13:2"
],
"Activity_Properties": {
"comment_count": 0,
"share_count": 0,
"like_count": 0
},
"#fieldTypes": "comments=n"
}
],
"notification": "Query executed in 0.01 sec. Returned 1 record(s)"
}
Output Query 2:
SELECT expand(#this.exclude('comments')) FROM (SELECT *, $comments as commentsList FROM Activities
LET $comments = (SELECT expand(#this.exclude('#rid')) FROM (SELECT username, comment, created_at FROM Comments WHERE #rid IN $parent.current.comments)))
{
"result": [
{
"#type": "d",
"#rid": "#12:0",
"#version": 1,
"#class": "Activities",
"activity_type_id": 1,
"username": "ultimaterandomuser",
"title": "random new activitie test",
"image": "http://www.someurl.com/images/blah.png",
"Activity_Properties": {
"comment_count": 0,
"share_count": 0,
"like_count": 0
},
"commentsList": [
{
"#type": "d",
"#version": 0,
"username": "randomuser1",
"comment": "randomuser1 comment",
"created_at": "2016-06-25 03:33:13",
"#fieldTypes": "created_at=t"
},
{
"#type": "d",
"#version": 0,
"username": "randomuser2",
"comment": "randomuser2 comment",
"created_at": "2016-06-25 03:33:13",
"#fieldTypes": "created_at=t"
},
{
"#type": "d",
"#version": 0,
"username": "randomuser3",
"comment": "randomuser3 comment",
"created_at": "2016-06-25 03:33:13",
"#fieldTypes": "created_at=t"
}
],
"#fieldTypes": "commentsList=z"
}
],
"notification": "Query executed in 0.041 sec. Returned 1 record(s)"
}
Hope it helps

Search in mongodb nested arrays

Here i have this database
{
"products": [
[
{
"title": "CS:GO:0",
"description": "500 x 6MM CARBON STEEL BALL BEARINGS",
"moreInfo": "SMK.",
"oldPrice": "269.99",
"newPrice": "109.99",
"offPrice": "59%",
"image": "",
"z-index": 0,
"shown": true,
"type": "product",
"category": "0",
"id": "0"
},
{
"title": "Grid autosport",
"description": "G&P G&P Tokyo Marui M870 Gas Charging...",
"moreInfo": "",
"oldPrice": "",
"newPrice": "129.99",
"offPrice": "",
"image": "",
"z-index": 1,
"shown": true,
"type": "product",
"category": "0",
"id": "1"
}
],
[
{
"title": "CS:GO:0",
"description": "500 x 6MM CARBON STEEL BALL BEARINGS",
"moreInfo": "SMK.",
"oldPrice": "269.99",
"newPrice": "109.99",
"offPrice": "59%",
"image": "",
"z-index": 0,
"shown": true,
"type": "product",
"category": "1",
"id": "0"
},
{
"title": "Grid autosport",
"description": "G&P G&P Tokyo Marui M870 Gas Charging...",
"moreInfo": "",
"oldPrice": "",
"newPrice": "129.99",
"offPrice": "",
"image": "",
"z-index": 1,
"shown": true,
"type": "product",
"category": "1",
"id": "1"
}
].........
I use this as a query to get the object i want
var query = {
"products": {
"$elemMatch": {
"category": '0',
"id": '0'
}
}
};
var secondaryQuery = {
'products.$': 1
};
collection.find(query, secondaryQuery)
The database returns null array [].
Does someone have idea why and how to get the object I want from it?