Schema less Nodes

已查看 58 次
跳至第一个未读帖子

parvat

未读,
2016年8月3日 04:02:422016/8/3
收件人 OrientDB
Hi, Can you help me on the below question

Can a define different properties to the vertex having same label's

Example:
Person with name,age ,gender
Person With name,gender ,salary

Here Person is the Vertex name.


Ideally i want to have a schema less nature .

Luigi Dell'Aquila

未读,
2016年8月3日 04:13:452016/8/3
收件人 orient-...@googlegroups.com
Hi,

What do you mean exactly? If you use schemaless approach, different vertices can have different properties of different types. 
You just have to avoid defining properties in the schema

Thanks

Luigi


--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

odbuser

未读,
2016年8月3日 23:59:112016/8/3
收件人 OrientDB
Is this what you are looking for?  You can mix schema-full and schema-less behavior.  I think the MANDATORY constraint is what you are looking for.

create class Person extends V;
create vertex
Person;
create property
Person.name STRING (MANDATORY TRUE,NOTNULL);
create property
Person.gender STRING (MANDATORY TRUE,NOTNULL);
create property
Person.salary INTEGER (MANDATORY FALSE,NOTNULL);

This means that name and gender are required and can't be null.
Salary is optional but when set it can't be null.

The following will work:
create vertex Person set gender="female",name='Jill'
create vertex
Person set gender="male",name='Sam',salary=400

The following will fail:
create vertex Person
create vertex
Person set name='Frank'
create vertex
Person set salary=null,gender="female",name='Jill'

parvat

未读,
2016年8月5日 07:22:582016/8/5
收件人 OrientDB
so if i do select from Person it will return all the not  mandatory fields  rite

odbuser

未读,
2016年8月6日 03:19:282016/8/6
收件人 orient-...@googlegroups.com
OrientDB is "schema-less" by default.  You may not understand the meaning of defined properties.  All properties are returned in select statements.  It does not filter the results based on property definitions.  Properties are used as constraints for inserts and updates.  They are also used when defining indexes.

Using my example, below are the results of the select on Person.  Notice that the properties are returned regardless of the property definitions.  Also note that you can add any arbitrary property name and value to a person and it will be returned as well.  Properties on vertices do not require property definitions on classes.  This is the schema-less behavior.  I'm not sure that this is properly explained in the documentation (
http://orientdb.com/docs/last/Java-Schema-Api.html) which makes it sound like there's actually a Schema full "mode" but there isn't.

If you don't define any properties on a class, then it's schema-less.
If you define some properties as mandatory on a class, then it's schema-hybrid.
If you define all properties as mandatory on a class, then it's nearly schema-full except that you can still add arbitrary property name/values to a vertex.  In other words, you can't prevent property name/values from being part of a vertex.  You can only require some of them using mandatory=true.

You might ask what the use of mandatory=false.  Well, properties are used when creating indexes so there will be cases were you don't want the property to be mandatory but you still want to use it in an index.


select from Person
+----+-----+------+------+----+------+
|#   |@RID |@CLASS|gender|name|salary|
+----+-----+------+------+----+------+
|0   |#49:2|Person|female|Jill|      |
|1   |#50:1|Person|male  |Sam |400   |
+----+-----+------+------+----+------+

Note that you can still create property name/values on a vertex without actually defining a property on the class.
e.g:

create vertex Person set name="Rena",gender="female",role="manager",cars=5,favoriteColor="green"
select from Person

+----+-----+------+------+----+------+-------+----+-------------+
|#   |@RID |@CLASS|gender|name|salary|role   |cars|favoriteColor|
+----+-----+------+------+----+------+-------+----+-------------+
|0   |#49:2|Person|female|Jill|500   |       |    |             |
|1   |#49:3|Person|female|Rena|      |manager|5   |green        |
|2   |#50:1|Person|male  |Sam |500   |       |    |             |
+----+-----+------+------+----+------+-------+----+-------------+


回复全部
回复作者
转发
0 个新帖子