如何在 OrientDB 中从字符串 属性 迁移到 Link?

How to migrate from a String property to a Link in OrientDB?

我在OrientDB中有一个Class,叫做Book。书中有一个author属性,是String类型的,包含作者姓名。我也有一个作者 class,作者的名字相同,但现在我想连接这两个 classes.

简而言之,我想将 author 属性 迁移到 LINK 引用,作者 class,其中有姓名、简介等。

所以我需要迁移我的图书,但我该怎么做才能不丢失我的数据?

你也可以执行类似的东西(我没试过):

update Book set author2 = (select from Author where name = $parent.current.author )
update Book set author = author2
update Book remove author2

我试过这个结构

我用过这个功能

var g=orient.getGraphNoTx();
var books=g.command("sql","select from Book");
var authors=g.command("sql","select from Author");
g.command("sql","create property Book.authors Link Author");
for(i=0;i<books.length;i++){
    var book_author=books[i].getProperty("author");
    for(j=0;j<authors.length;j++){
        var author=authors[j].getProperty("name");
        if(author==book_author){
            var query="update " + books[i].getId() + "set authors = " + authors[j].getId();
            g.command("sql",query);
        }
    }
}
g.command("sql","DROP PROPERTY Book.author FORCE");
g.command("sql","UPDATE Book REMOVE author");
g.command("sql","ALTER property Book.authors name author");
g.command("sql","UPDATE Book REMOVE authors");