orient.getGraph().command( "sql", "update Item set l_tags = '' where @rid in ?", [tagged] );
So you could try
var nearbyNodes = mydb.command('sql',"select in('Contributes_To') from " +originNode, []);
Notice the the empty array. Maybe it's a required parameter.
Answer 3:
Check out
https://github.com/orientechnologies/orientdb/issues/2390
Here's what I'm using (from above link without some logging code).
toJSObject = """
// This function should return a javascript object when you give it java object like List, Map, OResultSet etc. //
//function toJSObject(obj) {
function mapToJSObject(m) {
var ret = {};
// log("" + m + " IS A MAP (" + m.getClass() + ")");
var it = m.keySet().iterator();
while (it.hasNext()) {
var key = it.next();
ret[key] = toJSObject(m.get(key));
}
return ret;
};
function collectionToJSObject(c) {
var ret = [];
// log("" + c + " IS A COLLECTION (" + c.getClass() + ")");
var it = c.iterator();
while (it.hasNext()) {
ret.push(toJSObject(it.next()));
}
return ret;
};
if (obj == null) {
return "";
} else if (typeof obj == 'object') {
if (obj.getClass) {
//it's a java object !!!
var objClass = obj.getClass();
if (objClass == "class java.lang.String") {
return new String(obj);
} else if (objClass == "class java.lang.Integer" || objClass == "class java.lang.Long") {
return parseInt(obj);
} else if (objClass == "class java.lang.Float" || objClass == "class java.lang.Double") {
return parseFloat(obj);
} else if (obj.iterator) {
//Java COLLECTION (example ArrayList)
return collectionToJSObject(obj);
} else if (obj.keySet) {
//it's a Map (class java.util.HashMap for example)
return mapToJSObject(obj);
} else if (obj.getKey) {
// class java.util.LinkedHashMap
var ret = {};
ret[obj.getKey()] = toJSObject(obj.getValue());
return ret;
} else {
var ret = "[" + obj.getClass() + " Fields] ";
for (var key in obj) {
ret += key + ", ";
}
return ret;
}
} else {
var ret = {};
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
ret[key] = toJSObject(obj[key]);
}
}
return ret;
}
} else { //return as-is
return obj;
}
//}
"""
Other tips.1. Hook functions provide the 'doc' variable that you can use. For example.var val = doc.field('propName')2. See the following file for other methods provided by 'doc'core/src/main/java/com/orientechnologies/orient/core/record/impl/ODocument.java
3. If you are making changes in the hook function, be sure to
return 'RECORD_CHANGED';
4. Where java function requires a vararg (...), provide an array, even for single values. For example, to save an array to a field.var OType = com.orientechnologies.orient.core.metadata.schema.OType
doc.field('prop1', arrayValue, [OType.EMBEDDEDSET])
var mydb = orient.getGraph();
var nearbyNodes = mydb.command('sql',"select in('Contributes_To') from " +originNode, []);
var nearbyNodesID = nearbyNodes[0].getRecord().field('in');
Does this make sense? Do you have any other pointers?
If I try to use your function toJSObject for nearbyNodes, I get an error. If I use for nearbyNodesID I get JSON Object with some wrong parameters:[
{
"@type": "d",
"@version": 0,
"value": [
[
{
"name": "artigos indefinidos"
},
{
"in_Contributes_To": [
[
{
"out": "[class com.orientechnologies.orient.core.id.ORecordId Fields] valid, clusterPosition, next, temporary, hashCode, fromStream, wait, fromString, toStream, identity, isPersistent, notify, reset, copyFrom, getIdentity, notifyAll, copy, getClass, isTemporary, unlock, equals, isNew, compare, getClusterPosition, getClusterId, lock, class, compareTo, record, new, persistent, nextRid, toString, clusterId, isValid, getRecord, "
},
{
"in": "[class com.orientechnologies.orient.core.id.ORecordId Fields] valid, clusterPosition, next, temporary, hashCode, fromStream, wait, fromString, toStream, identity, isPersistent, notify, reset, copyFrom, getIdentity, notifyAll, copy, getClass, isTemporary, unlock, equals, isNew, compare, getClusterPosition, getClusterId, lock, class, compareTo, record, new, persistent, nextRid, toString, clusterId, isValid, getRecord, "
}
],
[
{
"out": "[class com.orientechnologies.orient.core.id.ORecordId Fields] valid, clusterPosition, next, temporary, hashCode, fromStream, wait, fromString, toStream, identity, isPersistent, notify, reset, copyFrom, getIdentity, notifyAll, copy, getClass, isTemporary, unlock, equals, isNew, compare, getClusterPosition, getClusterId, lock, class, compareTo, record, new, persistent, nextRid, toString, clusterId, isValid, getRecord, "
},
{
"in": "[class com.orientechnologies.orient.core.id.ORecordId Fields] valid, clusterPosition, next, temporary, hashCode, fromStream, wait, fromString, toStream, identity, isPersistent, notify, reset, copyFrom, getIdentity, notifyAll, copy, getClass, isTemporary, unlock, equals, isNew, compare, getClusterPosition, getClusterId, lock, class, compareTo, record, new, persistent, nextRid, toString, clusterId, isValid, getRecord, "
}
]
]
},
{
"out_Contributes_To": [
[
{
"out": "[class com.orientechnologies.orient.core.id.ORecordId Fields] valid, clusterPosition, next, temporary, hashCode, fromStream, wait, fromString, toStream, identity, isPersistent, notify, reset, copyFrom, getIdentity, notifyAll, copy, getClass, isTemporary, unlock, equals, isNew, compare, getClusterPosition, getClusterId, lock, class, compareTo, record, new, persistent, nextRid, toString, clusterId, isValid, getRecord, "
},
{
"in": "[class com.orientechnologies.orient.core.id.ORecordId Fields] valid, clusterPosition, next, temporary, hashCode, fromStream, wait, fromString, toStream, identity, isPersistent, notify, reset, copyFrom, getIdentity, notifyAll, copy, getClass, isTemporary, unlock, equals, isNew, compare, getClusterPosition, getClusterId, lock, class, compareTo, record, new, persistent, nextRid, toString, clusterId, isValid, getRecord, "
}
]
]
},
{
"activation": 0
}
],
....
etc.