BaseX - insert node {...} into //.. for multiple nodes - iteration

I am currently facing a problem with the BaseX native XML-Database.
I have got a sample dataset where I want to check whether a certain attribute in a certain node exists and if it does then set a value "true". If it doesn't exist I want to insert a new attribute. This is my code for a single Node:
if(fn:exists(//Dataset[#attribute="2"]/#b)) then
replace value of node //Dataset[#attribute="2"]/#b with "true"
else
insert node (attribute { 'b' } { "CREATED!" }) into //Dataset[#attribute="2"]
The problem I am facing at the moment is that I cannot find a way of iterating through all nodes of the type "Dataset" for example and check every single node.. It always says "Single element or document expected as insert target".

Okay, Googled for a long time but 15 minutes more would have saved me from posting this question:
for $dataset in //mondial/Dataset
let $DOCH := $dataset/#DOCH
return
if(fn:exists($DOCH)) then (
replace value of node $DOCH with "true")
else (
insert node (attribute DOCH {"true"}) into $dataset)

Related

Returning back the node name not the type/label?

if I have the following node :
> graph.query graph1 'create (jim:node)'
how do I query and get back the "jim"-value, not the 'node'-label
"jim" is not a value. It's a reference to the node you just created for future usage.
ex:
create (jim:node)
create (jack:node)
create (jim)-[:KNOWS]->(jack)
If you want to return the node you have created, you can simply write
create (jim:node) return jim
But keep in mind that it will not retrun the value "jim", it will return the node you capture with the reference "jim"
If you want to assign the value "jim" to the node, you must create a property on that node to store the value :
create (a:node {name:"Jim"}) return a.name

How to check if a Gun unordered list is empty?

Given the following, how would one go about determining if the machines list is empty in order to add a machine?
let gun = new Gun();
let machines = gun.get('machines');
How do I check if the machines list is empty?
This from Mark Nadal:
// machineId and location defined elsewhere
machines.val(table => {
if (Gun.obj.empty(table, '_') {
// table is empty so we can add something to it
let machine = gun.get('machine/' + machineId);
machine.put({machineId, location}};
machines.set(machine);
} else {
// table is not empty
})
table is a data node that has all the row pointers in it (not the actual sub-objects)
so if table has 0 items on it, then it is empty! Or if table is null or undefined
HOWEVER, gun has its {_: {...}} meta data it includes on every node, so you need to ignore that.
Gun.obj.empty({}) tests if an object is empty (you can use lodash or something else), the second parameter tells it to IGNORE a key, like in this case '_'. So it will still say that yes it is empty if it has 0 properties other than the metadata property.

EntityNotFoundException while firing a cypher

I am newbie to neo4j and I really need help.
I have created nodes properties NAME, EMAIL and AGE. These nodes are having relationship: IS_FRIEND_OF with property SINCE with other nodes.
I have given property values in NAME as “A”, “B”, “C”, “D” and so on.
Now when I fire a query in console like: Start n=node(*) where n.NAME=’A’ return n;
It is giving an exception like: EntityNotFoundException: The property 'NAME' does not exist on Node[0]
Now if I add a property NAME = “” on node [0] and then fire the same query, it is providing the correct output. For small data set it can work but for larger ones specifying each property for node [0] doesn’t seems to be the good solution.
Is it the only workaround or something else and better can be applied?
STARTn=node(*) WHERE n.NAME! = "A" RETURN n
The exclamation mark will do the following:
TRUE if n.prop = value, FALSE if n is NULL or n.prop does not exist
Cypher has two special operators: ? and ! to use in this case to handle this exception
Using ? will evaluate to true if n.prop is missing:
START n=node(*) WHERE n.NAME? = "A" RETURN n
And using ! will evaluate to false if n.prop is missing:
START n=node(*) WHERE n.NAME! = "A" RETURN n

Lucene indexes in Neo4j don't work as expected

I think that the title is a little bit vague, so I'm going to explain precisely my problem.
I am creating some nodes in Neo4j and then index them like this :
Index<Node> myindex = graphDb.index().forNodes(
"myindex",
MapUtil.stringMap(IndexManager.PROVIDER, "lucene", "type",
"fulltext"));
Node n = graphDb.createNode(); //create the node
node.setProperty("firstname", "firstname"); //add properties
node.setProperty("familyname", "familyname");
myindex.add(node, "familyname", "familyname"); //index it
But when I need to update Node "n" 's properties (for instance change "familyname" to "fname"), this node can't be found anymore through an index based search!
So before updating the property, this cypher query
start n= node:myindex(familyname:"familyname") return n
was returning the Node, whereas after update, I am expecting :
start n= node:myindex(familyname:"fname") return n
to return the same node with the new property, but it doesn't work ! While the first query is always working, like if the index is bound to the property "familyname"
Any thoughts about this ?
Thanks
So as tstorms suggested, the solution is to remove the index after updating the property :
n.setProperty("familyname","fname");
myindex.remove(n);
then add it with the new property :
myindex.add(n, "familyname","fname");

grid filter in dojo

can any one help with filtering multiple condition in dojo grid.
im using grid.DataGrid and json data.
data1 = {items: [ {"id":1,"media":"PRINT",pt:"Yellow Directory"},
{"id":2,"media":"DIGITAL",pt:"Social Media"},{id":3,"media":"DIGITAL",pt:"Yellow Online"}
],identifier: "id"};
a=1,b=2;
grid.filter({id:a,id:b})
the above line is just displaying the record with b value.
i need the record with both the values.
can any one help me with this.???
So you want the records that have any of the specified ids?
It comes down to the capabilities of the store you're using. If you're using a Memory store with SimpleQueryEngine, then you can specify a regex or an object with a test function instead:
grid.filter({id: {
test: function(x) {
return x === 'a' || x === 'b';
}
}});
If you're using JsonRest store, then you get to choose how your queries are processed server-side so you could potentially pass in an array of interesting values and handle that in your own way on the server. (i.e. filter({id:[a,b]}))