I have a question regarding data structure and rules ... I have content on which users can vote. Something like this:
Firestore object:
{
name: "Cat",
description: "A cat named Cat",
votes: 56
}
Now ... I want authenticated users to be able to have update access to the votes, but not to any other values of the object and of course read rights since the content has to be displayed.
I did this because I wanted to avoid additional queries when displaying the content.
Should I create another collection "votes" maybe where the votes are kept and for each document make an additional request to get them?
In rules, you have access to the state of the data both before and after the writes - so you can test specific fields to be sure they have not changed:
function existing() {
return resource.data;
}
function resulting() {
return request.resource.data;
}
function matchField(fieldName) {
return existing()[fieldName] == resulting()[fieldName];
}
....
allow update: if matchField("name") && matchField("description")
....
The functions just make the rule easier to read.
I have json file like this:
{"2020-04-28":
{
"37,N7L2H4,Carry,CHOPA,PLX":
{
"inter_results": {
"inter_mark": "GITA"
,"down": null
,"up": null
,"wiki": {"included": "false", "options": ["RRR", "SSS","HHH"]
}}
,"38, N5L2J4, HURT, SERRA, PZT": {
"inter_results": {
"inter_mark": "MARI"
,"down": "250"
,"up": "1250"
,"wiki": {"included": "true", "options": ["XXX", "YYY"]
}}
,"39, N4L2H4, HIBA, FILA, PFG": {
"inter_results": {
"inter_mark": "HILO"
,"down": "100"
,"up": "250"
,"wiki": {"included": "true", "options": ["RTG", "VTH","HJI","JKL"]
}}
}
}
And i want extract the Values N7L2H4,N5L2J4,N4L2H4 from this json file using tFileInputJson with jsonPath.
Using the native components of Talend, this is hard to achieve. You can do it with some java code but it's not elegant.
Here's a solution using json components suite from Talend Exchange which you can download here
The component tJSONDocTraverseFields allows you to list all fields, paths and values of your json.
It gives this output:
$.2020-04-28.37,N7L2H4,Carry,CHOPA,PLX.inter_results.inter_mark|4|inter_mark|"GITA"|false|21
$.2020-04-28.37,N7L2H4,Carry,CHOPA,PLX.inter_results.down|4|down|null|false|21
$.2020-04-28.37,N7L2H4,Carry,CHOPA,PLX.inter_results.up|4|up|null|false|21
$.2020-04-28.37,N7L2H4,Carry,CHOPA,PLX.inter_results.wiki.included|5|included|"false"|false|21
$.2020-04-28.37,N7L2H4,Carry,CHOPA,PLX.inter_results.wiki.options[0]|6|options|"RRR"|true|21
$.2020-04-28.37,N7L2H4,Carry,CHOPA,PLX.inter_results.wiki.options[1]|6|options|"SSS"|true|21
$.2020-04-28.37,N7L2H4,Carry,CHOPA,PLX.inter_results.wiki.options[2]|6|options|"HHH"|true|21
$.2020-04-28.38, N5L2J4, HURT, SERRA, PZT.inter_results.inter_mark|4|inter_mark|"MARI"|false|21
$.2020-04-28.38, N5L2J4, HURT, SERRA, PZT.inter_results.down|4|down|"250"|false|21
$.2020-04-28.38, N5L2J4, HURT, SERRA, PZT.inter_results.up|4|up|"1250"|false|21
You can then parse the json path to get the values you want:
I split the path by "." to get the field "37,N7L2H4,Carry,CHOPA,PLX", then split the result again on "," and get the first value.
tJSONDocOpen allows you to initialize your json file, it acts as a connection. You then select it in tJSONDocTraverseFields.
I have a nested JSON as shown below. I need to list down the values of all '.url' no matter how deeply it is nested.
{
section1: {
url: "abc/efg/dgh.com",
name: "test1"
},
section2: {
.section3: {
url: "efef/dedede/efdgh.com",
name: "test2"
}
}
}
The expected output is as follows:
["abc/efg/dgh.com", "efef/dedede/efdgh.com"]
Thanks in advance
If you need to access something "no matter how deeply it is nested", then recurse is your friend.
jq '[recurse|.url? // empty]' file.json
The question mark prevents us from failing when the recursion reaches something that is not an object (eg. the leaf strings). And //empty replaces the nulls we get from objects without an "url" key with empty results (so it deletes them).
The v3 has a specific API for retrieving the readme.md file. But in the new V4 GraphQL, there is no such field in the Repository Object.
Does anyone know how to retrieve the readme file?
Thanks!
There is not yet a specific entity to get the README.md file, but you can retrieve it as you would normally retrieve any other file:
{
repository(owner: "gitpoint", name: "git-point") {
object(expression: "master:README.md") {
... on Blob {
text
}
}
}
}
It looks like because the GitObject implements Blob, you can use the "... on" syntax to access it's properties, which will contain the contents of the object.
In order to access the object in question, pass in the branch and filename with the extension in the format "branch:filename.ext" and retrieve the Blob from the result, and the text from that.
Multiple objects can be retrieved simultaneously, allowing you to check for alternate casings, such as lowercase "readme.md" names. Simply provide aliases for the objects. Example below.
{
repository(owner: "owner", name: "name") {
upCase: object(expression: "master:README.md") {
... on Blob {
text
}
}
object(expression: "master:readme.md") {
... on Blob {
text
}
}
otherFile: object(expression: "master:index.js") {
... on Blob {
text
}
}
}
This may help explain the "... on" syntax.
https://graphql.github.io/graphql-spec/June2018/#sec-Inline-Fragments
I have a problem:
In Meteor, I would like to be able to first fetch data from mongodb and then be able to update/edit the fetched data before returning it to the template.
So for example I have movies in the database in the following format:
{ name: "...", released: "..." }
In the code i would do something like this:
var movie = Movies.findOne({name: "Inception"});
Then I would like to get and edit the "release" data from the movie -variable. How to do it?
Use a transform:
return Movies.find({}, {transform:function(movie) {
if(movie.release) movie.release = movie.release + " _ This has been appended to release".
return movie;
});