Patrick Hoeffel
Patrick Hoeffel

Reputation: 113

OrientDB creates a Record ID for every record. Many examples include an "ID" field of their own for classes. Which to use?

Is this a recommended practice, or should I be trying to use the @rid as the primary key for my classes?

The sample JSON Import page, for example, uses this record definition:

{
  "name": "Joe",
  "id": 1,  // <---- Surrogate key for this class
  "friends": [2,4,5],
  "enemies": [6]
 }

This makes it easier, I think, to create Edges that will work without having to query for the @rid of a just-inserted object as a load is going on.

Is this the recommended best practice?

Upvotes: 1

Views: 118

Answers (1)

Michela Bonizzi
Michela Bonizzi

Reputation: 2632

When OrientDB generates a record, it auto-assigns a unique unit identifier, called a Record ID, or RID. The syntax for the Record ID is the pound sign with the cluster identifier and the position. The format is like this:

#<cluster>:<position>

Records never lose their identifiers unless they are deleted. When deleted, OrientDB never recycles identifiers, except with local storage. Additionally, you can access records directly through their Record ID's. For this reason, you don't need to create a field to serve as the primary key, as you do in Relational databases.

Hope it helps

Regards

Upvotes: 0

Related Questions