I'm trying to return a specific node with the id (using neo4j-driver package within my nodejs server). I have the id of the node I'm searching for. So I used the parameters in the run method as showed bellow but I'm not getting any nodes.
session.run('MATCH (n:User)-[:OWN]->(a) WHERE id(n) = $id RETURN a',{id: idUser})
I checked and idUser-value is 128 and when i'm running this command, I get the right node.
session.run('MATCH (n:User)-[:OWN]->(a) WHERE id(n) = 128 RETURN a',{id: idUser})
Is there any one to make the first command working so I can get the node of the given id ?
Thanks
As it is written in the driver documentation:
Number written directly e.g. session.run("CREATE (n:Node {age:
{age}})", {age: 22}) will be of type Float in Neo4j. To write the age
as an integer the neo4j.int method should be used...
https://github.com/neo4j/neo4j-javascript-driver#write-integers
So when you pass the identifier from the node.js, you need to convert it:
session
.run('MATCH (n:User)-[:OWN]->(a) WHERE id(n) = $id RETURN a', {
id: neo4j.int(idUser)
})
or:
session
.run('MATCH (n:User)-[:OWN]->(a) WHERE id(n) = toInteger($id) RETURN a', {
id: idUser
})
Related
I have this really simple querybuilder in TypeOrm, working on a NodeJs with typescript backend and a MariaDB database
const queryBuilder = this.createQueryBuilder('cities')
return queryBuilder.where('cities.id = :q', { q }).take(limit).skip(offset).getMany()
and it is not passing the q parameter right, it outputs the following:
query: SELECT `cities`.`id` AS `cities_id`, `cities`.`state_id`
AS `cities_state_id`, `cities`.`name` AS `cities_name`, `cities`.`created_at` AS `cities_created_at`, `cities`.`updated_at`
AS `cities_updated_at` FROM `cities` `cities`
WHERE `cities`.`id` = ? LIMIT 8 -- PARAMETERS: ["2"]
I already tried passing just the q variable, it says that i have to pass an object literal so i pass the q parameter inside an object, i tried using the set parameter method as follows
return queryBuilder
.where('cities.id = :q', { q })
.setParameter('q', q)
.take(limit)
.skip(offset)
.getMany()
and its giving me the same output.
I am trying to pass a graph ql arguments array in cypher query. I am having difficulty making query work. I can see the parameter passed correctly while doing console log. However, when I try to utilize with node js. Neo4j driver is not doing anything. I think I am doing something wrong. Could anyone please guide me.
using neo4j 3.5.12
const query = `UNWIND $list as batch
match ((u:user { ohrid: ${ctx.ohrid}})-[:FILE_SHARED_WITH| FILE_SHARED_WITH_GROUP| MEMBER_OF_GROUP*..2]-(f:file)) where f.uuid = batch.uuid
SET f.documentStatus = batch.documentStatus
return f as files`;
const queryParams = { list: args.documents }; // args.document is arguments from gql mutation
const result = await session.run(query, queryParams);
if I use the same query in neo4j browser it works fine
UNWIND [{id: 2, documentStatus: "unpublished"}, { id: 32, documentStatus: "unpublished"}] as batch
match ((u:user { ohrid: 850046714})-[:FILE_SHARED_WITH| FILE_SHARED_WITH_GROUP| MEMBER_OF_GROUP*..2]-(f:file)) where ID(f) = batch.id and any(x in batch.documentStatus where x in ['published', 'unpublished'])
SET f.documentStatus = batch.documentStatus
return f
Cheers
~ Meet
I'm having trouble finding a way to iterate subnodes of a given node in puppeteer. I do not know the html structure beforehand, just the id of the parent element.
var elemId = "myelemid";
const doc = await page._client.send('DOM.getDocument');
const node = await page._client.send('DOM.querySelector', {
nodeId: doc.root.nodeId,
selector: '#' + elemId
});
//node.children empty
//node['object'].children empty
//try requesting childnodes
var id = node.nodeId;
var childNodes = await page._client.send('DOM.requestChildNodes', {
nodeId: id
});
//childNodes empty
//try requesting by resolveNode?
var aNode = await page._client.send('DOM.resolveNode', {
nodeId: id
});
//aNode.children is empty
Is there a way to get the children of a node if you don't know the html structure in puppeteer?
What I would do here is to use the evaluate method of Puppeteer to return the children elements of your node to your script as follows:
const nodeChildren = await page.$eval(cssSelector, (uiElement) => {
return uiElement.children;
});
console.log(nodeChildren); // Outputs the array of the nodes children
Hope this helps!
I ended up using page.evaluate to run some js that adds unique classnames to every element and subelement I want analyzed and then pass that back as JSON string since page.evaluate only returns a string. Then I just call DOM.querySelector on each of those unique selectors and loop through them that way.
Returning children from page.$eval doesn't give me protocol nodes that I can run more dev protocol functions on, and xpath doesn't solve my real problem because it can't recursively loop through all sub-children, then the sub-children of those children.
I'm closing the issue since labeling using unique classnames solves my problem.
model
asset Route identified by route_id {
o String route_id
o String rider_id
o String parcel_id
}
transaction assignParcelToRider {
o String rider_id
o String parcel_id
}
logic.js
var assetRegistry;
var id = assignValue.rider_id;
return getAssetRegistry('org.rytle.Route').then(function(ar) {
assetRegistry = ar;
return assetRegistry.get(id);
}).then(function(asset) {
asset.parcel_id = assignValue.parcel_id;
return assetRegistry.update(asset);
});
Here I want to find the rider_id and update parcel_id there. But here its not finding the rider_id.
The main thing is you need to get the asset, by the asset identifier when using .get() and rider_id is not that, in your model.
Also - may need more info - but it all rests on id getting a value from assignValue.rider_id and I can't tell how that was defined / asserted and whether it is within scope. I can see that id however, should be in scope for your function below - but using the correct identifier for an asset, this should work (as an example):
return getAssetRegistry('org.rytle.Route').then(function(ar) {
return ar.get(route_id) // or whatever you've assigned it to or txnobject.route.getIdentifier()); // ie you must get the asset by identifier
}).then(function(asset) {
asset.parcel_id = id;
return ar.update(asset);
});
and so on;
ps you can check out sample-networks for some examples (eg under 'test' directory) - note these now use async / await functions (instead of 'promises' shown above) which came in with Node 8 (and is far easier to write than using promises FYI)
I'm using the Neo4jphp REST API and I'm having a problem of relating a node iv created in my code to a node im retrieving from the neo4j database.
I'm retrieving the node as follows
$querystring="MATCH(n)"."WHERE has (n.name) and n.name='Interests'"."RETURN n";
$query=new Everyman\Neo4j\Cypher\Query($client,$querystring);
$result=$query->getResultSet();
im creating another node in my code using createNode()
$friend=$client->makeNode()->setProperty('name',$fname)->save();
I used relateTo() to relate them
$m=$client->getNode($result);
$m->relateTo($friend,$movi)->save();//$movi is a common movie name
but getting this error
PHP Catchable fatal error: Object of class Everyman\\Neo4j\\Query\\ResultSet could not be converted to string in /var/www/vendor/everyman/neo4jphp/lib/Everyman/Neo4j/Cache/EntityCache.php
would really appreciate any input
A neo4jphp query returns a row object (even if theres only one responce) so
$m=$client->getNode($result);
won't work
try this instead
$querystring="MATCH(n) WHERE has (n.name) and n.name='Interests' RETURN n";
$query=new Everyman\Neo4j\Cypher\Query($client,$querystring);
$result=$query->getResultSet();
foreach($result as $resultItem)
{
$resultArray[] = $resultItem['x'];
//$resultItem['x'] is the node object, now $result array is an array of node objects
}
$friend= $client->makeNode()->setProperty('name',$fname)->save();
$resultArray[0]->relateTo($friend,$movi)->save();
this code will also work with this query (easier to read)
$querystring="MATCH (n {name:"Interests"}) RETURN n";
I would do it this way:
$queryString = "MATCH(n) WHERE has (n.name) and n.name= {name} RETURN ID(n)";
$query = new Everyman\Neo4j\Cypher\Query($client,$queryString,array('name'=>'Interests'));
$result = $query->getResultSet();
$resultArray=array();
foreach($result as $row)
{
array_push($resultArray,$row['n']);
}
$friend = $client->getNode($resultArray[0]);
$friend->relateTo($friend,$movi)-save();