Why does the request query value appear strange? - node.js

I'm making an API using Express. The request query was sent via Postman to test the GET request, but the desired result is not available.
For example, Postman created a query as below and requested it.
Key : userId, Value : 1
Key : routine[], Value : routine-ZMp#%26nSqOTv1Tsf$459Xp8Ku
Key : routine[], Value : routine-mC%26w*CU!tvTA(RE4pE%234J1d#
Key : routine[], Value : routine-Hn%23fmJ0*90AR%H)6ayLUN$TP
Key : routine[], Value : routine-%23fm%23JO
The expected log value of the routine array on the actual API server is as follows.
[routine-ZMp#&nSqOTv1Tsf$459Xp8Ku, routine-mC&w*CU!tvTA(RE4pE#4J1d#, routine-Hn#fmJ0*90AR%H)6ayLUN$TP, routine-#fm#JO]
Here's the actual log result.
[routine-ZMp#&nSqOTv1Tsf$459Xp8Ku, routine-mC&w*CU!tvTA(RE4pE#4J1d#, routine-Hn%23fmJ0*90AR%H)6ayLUN$TP, routine-#fm#JO]
The log is being output without changing the value of the second index from %23 to #. Strangely, the value of the third index is converted normally. I don't understand what the problem is. Why do you get this result?

decodeURIComponent("routine-Hn%23fmJ0*90AR%H)6ayLUN$TP")
throws a "URI malformed exception", because the % preceding the H is not percent-encoded. I assume that this value is therefore left un-decoded. The correctly encoded query value would be
Key : routine[], Value : routine-Hn%23fmJ0*90AR%25H)6ayLUN$TP

Related

Nodejs (Infinispan) : Does Infinispan put method returns null for key inserted in cache for first time?

I have been reviewing the infinispan documentation and overloaded put method returns the value being replaced, or null if nothing is being replaced.
I am using overloaded put method with nodejs and it's not returning expected data, getting undefined.
how can I achieve this with nodejs?
Looked at the documentation, need assistance to understand the behavior with Nodejs
Documentation Link : https://docs.jboss.org/infinispan/9.2/apidocs/org/infinispan/commons/api/BasicCache.html#put-K-V-
V put(K key,
V value,
long lifespan,
TimeUnit unit)
An overloaded form of put(Object, Object), which takes in lifespan parameters.
Parameters:
key - key to use
value - value to store
lifespan - lifespan of the entry. Negative values are interpreted as unlimited lifespan.
unit - unit of measurement for the lifespan
Returns:
the value being replaced, or null if nothing is being replaced.
Looked at the documentation, need assistance to understand the behavior with Nodejs
From https://github.com/infinispan/js-client/blob/main/lib/infinispan.js#L327 it looks like put's third argument opts can have property previous that makes it return the old value, so try:
const oldValue = client.put('key', 'value', { previous: true })

How can I retrive an element value from array in gfsh

I have the following data in gfsh DB:
gfsh>query --query="select * from /siteinfo"
Result : true
Limit : 100
Rows : 4
Result
----------------------------------------------------------------------------------------------------------
{"id":"9347292b-cad8-4837-92b0-df34b8083901","lastUpdateTime":"1646376430201","fqdn":"test03.east.net","weight":1,"administrativeState":"unlocked","distributedSystemId":"3","lastSeenPeerUpdateTime":["4:1646376427321","1:1646376427321","2:1646376427321","3:1646376427321"],"siteLeader":false}
{"id":"1493a604-1ea2-44fa-9fe4-3cb99ed8d71b","lastUpdateTime":"1646376431751","fqdn":"test01.east.net","weight":1,"administrativeState":"unlocked","distributedSystemId":"1","lastSeenPeerUpdateTime":["2:1646376431235","4:1646376431235","3:1646376431235","1:1646376431235"],"siteLeader":true}
{"id":"73ddaee1-e586-42ce-8a78-c5c3ad324bba","lastUpdateTime":"1646376430995","fqdn":"test02.east.net","weight":1,"administrativeState":"unlocked","distributedSystemId":"2","lastSeenPeerUpdateTime":["2:1646376429276","4:1646376429276","1:1646376429276","3:1646376429276"],"siteLeader":false}
{"id":"150f58b5-e43e-40ef-a25d-2c5f2a69c06b","lastUpdateTime":"1646376430783","fqdn":"test04.east.net","weight":1,"administrativeState":"unlocked","distributedSystemId":"4","lastSeenPeerUpdateTime":["1:test","2:test","3:test","4:test"],"siteLeader":false}
You may see that there is no specific title in the result.(the 'Result' word is returned by gfsh)
gfsh>query --query="select e.value.Result from /siteinfo.entries e"
Result : true
Limit : 100
Rows : 4
Value
---------
UNDEFINED
UNDEFINED
UNDEFINED
UNDEFINED
How can I retrive the 'fqdn' only for 'siteLeader' is 'true'?
I'm not sure what the question is here, because this is directly in the Querying FAQ and Examples: Can I see query string examples, listed by query type? page and not all that much different from regular SQL:
select s.fqdn from /siteinfo s where s.siteLeader = true

How can I search for a null value in Orchestrate?

I'm trying to figure out how I can query for a non-existent or null value key in Orchestrate. This doesn't return any results:
db.search('events', 'value.originalDocument: null')
In the dashboard, I can see the key is there, and has a null value.

ArangoDB examples: match anything with a key of x?

Many (all?) of ArangoDB's graph functions accept an "example" document. The documentation for the example parameter says:
{} : Returns all possible vertices for this graph
idString : Returns the vertex/edge with the id idString
[idString1, idString2 ...] : Returns the vertices/edges with the ids matching the given strings.
{key1 : value1, key2 : value2} : Returns the vertices/edges that match this example, which means that both have key1 and key2 with the corresponding attributes
{key1.key2 : value1, key3 : value2} : It is possible to chain keys, which means that a document {key1 : {key2 : value1}, key3 : value2} would be a match
[{key1 : value1}, {key2 : value2}] : Returns the vertices/edges that match one of the examples, which means that either key1 or key2 are set with the corresponding value
In each of these cases (except the idString), it seems I am providing both a key and a value for Arango to match against.
Is there a way for me to create an example that would match any document that has a specific key (as long as the value is not null)?
Just for illustration, here I would like to get any neighboring vertex that has a key of "actor" and I don't care what the value of that key is (as long as it has one):
db._query('RETURN GRAPH_NEIGHBORS("movies", {movie: "Scarfies"}, {neighborExamples: [{actor: *}]})').toArray()
Is this possible in ArangoDB?
I don't think this is possible to do at the moment, because in the examples you cannot specify wildcards.
As we recently added custom visitors options to several other graph functions, it would be straight forward to add this possibility for GRAPH_NEIGHBORS, too.
The visitor would look like this then:
var func = function (config, result, vertex, path) {
if (vertex.hasOwnProperty('actor')) {
return vertex;
}
};
require("org/arangodb/aql/functions").register("my::actorVisitor", func);
And the AQL query to get the neighbors of interest:
RETURN GRAPH_NEIGHBORS("movies", { movie: "Scarfies" }, {
visitorReturnsResult: true,
visitor: "my::actorVisitor"
})
Not sure if this is the best option, but at least it would produce the desired result. If you think this is sensible just let us know so we can add this in 2.4.4

Insert data into REDIS (node.js + redis)

How, i can insert (store) data something like this (node.js + redis):
var timestamp = new Date().getTime();
client.hmset('room:'+room, {
'enabled' : true,
timestamp : {
'g1' : 0,
'g2' : 0
}
});
and how affter that i can do increment for g1 or g2 ?
P.S. when insert timestamp this way, redis-cli show timestamp instead UNIX time
You're looking for a combination of HMGET and HMSET. According to the docs:
HMGET key field [field ...]
Returns the values associated with the specified fields in the hash
stored at key.
For every field that does not exist in the hash, a nil value is
returned. Because a non-existing keys are treated as empty hashes,
running HMGET against a non-existing key will return a list of nil
values.
HMSET key field value [field value ...]
Sets the specified fields to their respective values in the hash
stored at key. This command overwrites any existing fields in the
hash. If key does not exist, a new key holding a hash is created.
What you want to do, then, is retrieve your value from the has, perform any operations on it that seem appropriate, and save over the previous value.
Another, possibly better solution, would be to use HINCRBY. Provided you stick with a timestamp, you can increment the field without performing a get operation:
HINCRBY key field increment
Increments the number stored at field in the hash stored at key by
increment. If key does not exist, a new key holding a hash is created.
If field does not exist the value is set to 0 before the operation is
performed.
The range of values supported by HINCRBY is limited to 64 bit signed
integers.
You probably will need to restructure your hash for this to work though, unless there is a way to drill down to your g1/g2 fields (stackoverflow community, feel free to edit this answer or comment it if you know a way). A structure like this should work:
{
enabled : true,
timestamp_g1 : 0,
timestamp_g2 : 0
}

Resources