I am using Orientdb 2.2.10.
What I want to achieve?
I want to get a vertex of a particular vertexType
- e.g vertexType = 'Person'.
My graphdb is indexed with unique key('uid').
What I am doing to achieve it?
getVertices(lable, []iKey, []iValue)
I am getting the desire vertex
what is problem with this method? :-
I am getting the desire vertex even when I provide any label(which is present in the database) name
e.g:-
I want to get a vertex of vertextype = 'Person' having uid = 'ram'
I am getting this vertex even when I provide any label (e.g "Relation") which is present in database.
Is this a bug or I am doing something wrong?
Thanks..!
I replicated your structure.
I have tried with this code
String [] keys=new String[]{"uid"};
String [] values=new String[]{"ram"};
Iterable<Vertex> it= g.getVertices("Person", keys, values);
for(Vertex v:it){
System.out.println(v.getId());
System.out.println(v.getProperty("uid"));
}
and I obtained
#21:0
ram
while with
String [] keys=new String[]{"uid"};
String [] values=new String[]{"ram"};
Iterable<Vertex> it= g.getVertices("Relational", keys, values);
for(Vertex v:it){
System.out.println(v.getId());
System.out.println(v.getProperty("uid"));
}
I got nothing.
Hope it helps.
Related
I want to create a simple collection that stores statistics of different devices.
Each device has a unique device id. I want to enforce the uniqueness so I thought to create a unique index for the device id field, But I didn't figured how to tell the collection that this field is of type number.
For example I can receive query with device id '0x3f', '0x0003f', '3f'... and all of them need to match to the same document.
I can parse the request before querying the DB but to me it's not sound like the right solution...
I suggest not worrying about this in Mongo, but instead trying to handle it in your application layer which is calling Mongo. For example, in JavaScript, appreciate that using any hex literal translates to the same integer value:
var i = 0x3f;
var j = 0x0003f;
if (i == 63) {
console.log("0x3f = 63");
}
if (j == 63) {
console.log("0x0003f = 63");
}
That is, just let the application marshall the hex literal into an integer value, then pass that int value to Mongo.
I'm looking to create a count of my 'trolleys' field which is dynamic. This should count the number of trolleys on any given day by the type (e.g. a,b,c). However, I don't want to create a static column which only counts by the type (A,B,C). However, instead I would require a dynamic count which would count depending on the 'type' as we currently don't know which types will be used as this would change on a day to day basis.
Sample data:
I'm looking to create this in Ireport 5.6.
Proposed Outcome
Any ideas would be excellent :)
You can use HashMap to count your fields, like this.
public Map<String, List<Class>> sortByKey(List<Class> values){
Map<String, List<Class>> map = new HashMap<>();
for(Class value : values){
if(map.containsKey(value.type)){
List<Class> valueByKey = map.get(value.type);
valueByKey.add(value);
}
else{
List<Class> newValues = new ArrayList<>();
newValues.add(value);
map.put(value.type, newValues);
}
}
return map;
}
Code above sort your data by key, which is in your example "type" field. You can then get number of each type by checking the size of the list by the specific key. Example bellow.
List<Class> tmp = map.get("a");
int count = tmp.size();
Is there a way to map Tinkerpop Frames's #Adjacency annotated property to Orientdb LINKLIST? Right now I've something like this:
interface Person {
#Adjacency(label = "personCars", direction = Direction.OUT)
Iterable<Car> getCars();
#Adjacency(label = "personCars", direction = Direction.OUT)
void addCar(Car car);
}
I want this to be mapped to LINKLIST in Orientdb database to keep an order of added vertices. But this is by default mapped to LINKBAG type. Is there any clean solution to set Orientdb to map adjacencies to LINKLISTs?
OrientDB, by default, uses a set to handle the edge collection. Sometimes it's better having an ordered list to access the edge by an offset. Example:
person.createEdgeProperty(Direction.OUT, "Photos").setOrdered(true);
Every time you access the edge collection the edges are ordered. Below is an example to print all the photos in an ordered way.
for (Edge e : loadedPerson.getEdges(Direction.OUT, "Photos")) {
System.out.println( "Photo name: " + e.getVertex(Direction.IN).getProperty("name") );
}
To access the underlying edge list you have to use the Document Database API. Here's an example to swap the 10th photo with the last.
// REPLACE EDGE Photos
List<ODocument> photos = loadedPerson.getRecord().field("out_Photos");
photos.add(photos.remove(9));
From the official documentation.
Is there a way to create with ArangoDB an Edge with REST API without knowing the Vertex ids? With a query to find the vertexs and link them?
Like this with OrientDB: create edge Uses from (select from Module where name = 'm2') to (select from Project where name = 'p1')
I don't want to query via REST the two vertex before, and after create the Edge. I don't want to use Foxx also.
Perhaps with AQL?
Thanks.
Yes, it is doable with a single AQL query:
LET from = (FOR doc IN Module FILTER doc.name == 'm2' RETURN doc._id)
LET to = (FOR doc IN Project FILTER doc.name == 'p1' RETURN doc._id)
INSERT {
_from: from[0],
_to: to[0],
/* insert other edge attributes here as needed */
someOtherAttribute: "someValue"
}
INTO nameOfEdgeCollection
First I'd like to show the corresponding code snippet. When it comes to objCtx.AttachTo() it throws me an error:
Error: "The object cannot be attached because the value of a property that is a part of the EntityKey does not match the corresponding value in the EntityKey."
// convert string fragIds to Guid fragIds
var fragIdsGuids = docGenResult.FragIds.Select(c => new Guid(c)).ToList();
//add each fragment to document))))
foreach (Guid fragIdsGuid in fragIdsGuids)
{
var fragment = new Fragment() { EntityKey = new EntityKey("DocTestObjectContext.Fragments", "ID", fragIdsGuid) };
objCtx.AttachTo("Fragments", fragment);
}
objCtx.SaveChanges();
I've checked everything and I'm not missing any primary key.
However I need some words to explain why I think I have to do it this way.
I'm using EF4 in a C# Environment.
I have a many to many relationship between two tables, Document and Fragments(Primary key "ID") (Documents can have many fragments and a fragment can be a part of many documents)
The Entity Model works fine for me.
However when I try to add a new document to the DB I already have the IDs of the related Fragments in my hand. For adding a new document to the DB I have to call each Fragmentobject and add it to the mapped reference in my document-object. This is a bottleneck because a document can have more than 1000 fragments. The Consequence is that I need 1sec per document. Not much, but I have to create more than 3000 documents and saving this second would result in more speed.
Hopefully you know what's wrong in here.
Thanks.
Thomas
1st edit:
here is the solution wich actually works. I would like to avoid to load all the fragments and instead just save the fragment GUID I already have in the mapping table.
// convert string fragIds to Guid fragIds
var fragIdsGuids = docGenResult.FragIds.Select(c => new Guid(c)).ToList();
// get responding entities from Fragment table
var fragmentList = objCtx.Fragments.Where(c => fragIdsGuids.Contains(c.ID)).ToList();
foreach (var fragment in fragmentList)
{
doc.Fragment.Add(fragment);
}
objCtx.SaveChanges();
2nd edit:
I have the feeling that it is not really clear what I try to do.
However I would like to link/reference existing fragments in a Fragment-table to a coressponding Document in a Document table. The Document I'd like to reference is a new one. The document to Fragment table has an many to many relationship. This relationship has a linking table on the database. In the model it is correctly modeled as a many to many relationship. That's fine.
So far so good. What works is what you can see under my first edit. I have to load all the necessary fragments for a document by their id
// get responding entities from Fragment table
var fragmentList = objCtx.Fragments.Where(c => fragIdsGuids.Contains(c.ID)).ToList();
After that I'm able to add them to my document entity:
foreach (var fragment in fragmentList)
{
doc.Fragment.Add(fragment);
}
But why the hell do I have to load the whole entity (fragments) only to link it to a new document. Why do not tell the EntityStateManager "Dude, here you have some Fragment IDs, link them!"?
Further I tried to follow the MSDN article mentioned by Adrian in the comments. This doesn't worked out for me.
I'll try this:
var fragment = new Fragment {ID = fragIdsGuid};
//fragment.EntityKey.Dump(); // -- this should be null
objCtx.AttachTo("Fragments", fragment);
//fragment.EntityKey.Dump(); // -- shows the EntityKey object, created after the object is attached
The Dump function is from LinqPad