Search code examples
orientdb

How to insert objects with links and retrieve them


I'm trying this with curl:

first insert a document:

curl --user admin:admin -X POST -d '{"@class":"Question"}' http://127.0.0.1:2480/document/home/
{"@type":"d","@rid":"#13:3","@version":6,"@class":"Question"}

second insert a document with a reference to the first one inside the items list

curl --user admin:admin -X POST -d '{"@class":"Question", "items":[{"@rid":"#13:3"}]}' http://127.0.0.1:2480/document/home/
{"@type":"d","@rid":"#13:2","@version":2,"@class":"Question","items":[{"@rid":"#13:3"}]}

finally I tried to get the last document:

curl --user admin:admin -X GET http://127.0.0.1:2480/document/home/13:2
{"@type":"d","@rid":"#13:2","@version":2,"@class":"Question","items":[{"@rid":"#13:3"}]}

But I need this:

{"@type":"d","@rid":"#13:2","@version":2,"@class":"Question","items":[{"@type":"d","@rid":"#13:3","@version":6,"@class":"Question"}]}

This is the documentation page:

https://github.com/orientechnologies/orientdb/wiki/OrientDB-REST

Edit:

I tried this and it did not work

curl --user admin:admin -X GET http://127.0.0.1:2480/document/home/13:2/*:-1
{"@type":"d","@rid":"#13:2","@version":2,"@class":"Question","items":[{"@rid":"#13:3"}]}

Solution

  • The second insert must contains the RID only:

    {"@type":"d","@rid":"#13:2","@version":2,"@class":"Question","items":["#13:3"]}
    

    To retrieve the full tree/graph set the fetch plan. Take a look at: https://github.com/orientechnologies/orientdb/wiki/OrientDB-REST#get---document

    Use:

    curl --user admin:admin -X GET http://127.0.0.1:2480/document/home/13:2/*:-1