我使用OVertex和OEdge来存储数据点。我的数据点可能是重复的和不唯一的,如何确保orientdb存储它们的唯一性(基于某个属性)。我似乎在文档中找不到任何有帮助的东西。我使用的是orientdb 3.0。我正在寻找一种使用Java多模型API来做到这一点的方法。
发布于 2020-04-28 19:12:42
您可以在属性上创建唯一索引:
CREATE INDEX Person.uuid on Person(uuid) UNIQUE有关索引的完整文档在此处:http://orientdb.com/docs/3.0.x/sql/SQL-Create-Index.html
发布于 2020-05-05 12:55:56
如果您正在使用JAVA多模型API,我发现的最简洁的方法是:
// create the connection pool for orientdb
OrientDB orient = new OrientDB(orientUrl, OrientDBConfig.defaultConfig());
OrientDBConfigBuilder poolCfg = OrientDBConfig.builder();
poolCfg.addConfig(OGlobalConfiguration.DB_POOL_MIN, 2);
poolCfg.addConfig(OGlobalConfiguration.DB_POOL_MAX, 5);
ODatabasePool pool = new ODatabasePool(orientUrl, databaseName, orientUser, orientPass, poolCfg.build());
// acquire the orient pool connection
try (ODatabaseSession db = pool.acquire()) {
// check and create vertex/edge class
if (db.getClass("className") == null) {
// create the class if it does not exist in the DB
OClass orientClass =
db.createVertexClass("className");
// OR db.createEdgeClass("className");
orientClass.createProperty("id", OType.STRING);
orientClass.createIndex("id", OClass.INDEX_TYPE.UNIQUE, "id");
}
// now create the OVertex/OEdge/OElement
OVertex vertex = db.newVertex("className");
// add properties to your document
vertex.setProperty("id", id);
...
// release the connection back to the pool
} finally {
orient.close();
}我还没有在文档中找到这一点,所以它可能对某些人有帮助。
https://stackoverflow.com/questions/61440909
复制相似问题