OrientDB DEMODB Database Queries

Connect to OrientDB console

krishna@ubuntu:/opt/orientdb/bin$ ./console.sh

OrientDB console v.3.0.0m2 (build 31b455cec3cc97d11be0748e31ed1a03ff6a23ac) https://www.orientdb.com
Type 'help' to display all the supported commands.
orientdb>

orientdb>

Connect to localhost

orientdb> CONNECT remote:localhost root admin

Disconnecting from the database [null]...OK
Connecting to remote Server instance [remote:localhost] with user 'root'...OK
orientdb {server=remote:localhost/}>

Connect to localhost with demodb database

orientdb> CONNECT remote:localhost/demodb root admin

Connecting to database [remote:localhost/demodb] with user 'root'...OK
orientdb {db=demodb}>

List Databases

orientdb {server=remote:localhost/}> LIST databases

Found 1 databases:

* demodb (remote)

orientdb {server=remote:localhost/}>

Connect to demodb database

orientdb {server=remote:localhost/}> CONNECT remote:localhost/demodb root admin

Disconnecting from remote server [remote:localhost/]...
OK
Connecting to database [remote:localhost/demodb] with user 'root'...OK
orientdb {db=demodb}>

Select all the vertices (Vertex)

orientdb {db=demodb}> SELECT from V

+----+------+---------+----+----+------------------------+---------------------------------+
|#   |@RID  |@CLASS   |Id  |Code|Name                    |in_IsFromCountry                 |
+----+------+---------+----+----+------------------------+---------------------------------+
|0   |#33:0 |Countries|1   |AD  |Andorra                 |                                 |
|1   |#33:1 |Countries|9   |AQ  |Antarctica              |[#146:46]                        |
|2   |#33:2 |Countries|17  |BA  |Bosnia and Herzegovina  |[#148:20]                        |
|3   |#33:3 |Countries|25  |BJ  |Benin                   |                                 |
|4   |#33:4 |Countries|33  |BT  |Bhutan                  |                                 |
|5   |#33:5 |Countries|41  |CF  |Central African Republic|[#147:11,#151:37,#151:47]        |
|6   |#33:6 |Countries|49  |CO  |Colombia                |[#148:4,#145:12,#150:42]         |
|7   |#33:7 |Countries|57  |DE  |Germany                 |                                 |
|8   |#33:8 |Countries|65  |EG  |Egypt                   |[#146:28]                        |
|9   |#33:9 |Countries|73  |FM  |Micronesia              |[#146:13,#150:41]                |
|10  |#33:10|Countries|81  |GG  |Guernsey                |[#148:38]                        |
|11  |#33:11|Countries|89  |GR  |Greece                  |[#147:23]                        |
|12  |#33:12|Countries|97  |HN  |Honduras                |[#152:21,#149:33,#150:35,#152:45]|
|13  |#33:13|Countries|105 |IN  |India                   |[#152:20]                        |
|14  |#33:14|Countries|113 |JO  |Jordan                  |[#145:13,#151:43]                |
|15  |#33:15|Countries|121 |KP  |North Korea             |                                 |
|16  |#33:16|Countries|129 |LI  |Liechtenstein           |                                 |
|17  |#33:17|Countries|137 |MA  |Morocco                 |[#149:14,#145:17,#150:18]        |
|18  |#33:18|Countries|145 |ML  |Mali                    |                                 |
|19  |#33:19|Countries|153 |MT  |Malta                   |[#148:5]                         |
+----+------+---------+----+----+------------------------+---------------------------------+
LIMIT EXCEEDED: resultset contains more items not displayed (limit=20)

20 item(s) found. Query executed in 2.133 sec(s).
orientdb {db=demodb}>

Select all the edges (Edges)

orientdb {db=demodb}> SELECT from E

+----+-------+-------------+-------+------+
|#   |@RID   |@CLASS       |out    |in    |
+----+-------+-------------+-------+------+
|0   |#145:0 |IsFromCountry|#121:0 |#33:29|
|1   |#145:1 |IsFromCountry|#121:1 |#40:11|
|2   |#145:2 |IsFromCountry|#121:2 |#37:0 |
|3   |#145:3 |IsFromCountry|#121:3 |#36:29|
|4   |#145:4 |IsFromCountry|#121:4 |#36:2 |
|5   |#145:5 |IsFromCountry|#121:5 |#34:12|
|6   |#145:6 |IsFromCountry|#121:6 |#35:7 |
|7   |#145:7 |IsFromCountry|#121:7 |#35:10|
|8   |#145:8 |IsFromCountry|#121:8 |#35:6 |
|9   |#145:9 |IsFromCountry|#121:9 |#33:25|
|10  |#145:10|IsFromCountry|#121:10|#36:18|
|11  |#145:11|IsFromCountry|#121:11|#38:9 |
|12  |#145:12|IsFromCountry|#121:12|#33:6 |
|13  |#145:13|IsFromCountry|#121:13|#33:14|
|14  |#145:14|IsFromCountry|#121:14|#34:3 |
|15  |#145:15|IsFromCountry|#121:15|#38:20|
|16  |#145:16|IsFromCountry|#121:16|#35:5 |
|17  |#145:17|IsFromCountry|#121:17|#33:17|
|18  |#145:18|IsFromCountry|#121:18|#39:10|
|19  |#145:19|IsFromCountry|#121:19|#37:9 |
+----+-------+-------------+-------+------+
LIMIT EXCEEDED: resultset contains more items not displayed (limit=20)

20 item(s) found. Query executed in 1.517 sec(s).
orientdb {db=demodb}>

List all the classes

orientdb {db=demodb}> LIST CLASSES


CLASSES
+----+-----+-------------+-------------+-------------------------------------------------------------------------------------------------------------------+
|#   |COUNT|NAME         |SUPER-CLASSES|CLUSTERS                                                                                                           |
+----+-----+-------------+-------------+-------------------------------------------------------------------------------------------------------------------+
|0   |    5|_studio      |             |_studio(225),_studio_1(226),_studio_2(227),_studio_3(228),_studio_4(229),_studio_5(230),_studio_6(231),_studio_7...|
|1   |   55|Archaeolog...|[V, Attrac...|archaeologicalsites(113),archaeologicalsites_1(114),archaeologicalsites_2(115),archaeologicalsites_3(116),archae...|
|2   |    0|Attractions  |[V, Locati...|attractions(81),attractions_1(82),attractions_2(83),attractions_3(84),attractions_4(85),attractions_5(86),attrac...|
|3   |  127|Castles      |[V, Attrac...|castles(97),castles_1(98),castles_2(99),castles_3(100),castles_4(101),castles_5(102),castles_6(103),castles_7(104) |
|4   |  249|Countries    |[V]          |countries(33),countries_1(34),countries_2(35),countries_3(36),countries_4(37),countries_5(38),countries_6(39),co...|
|5   |  400|Customers    |[V]          |customers(121),customers_1(122),customers_2(123),customers_3(124),customers_4(125),customers_5(126),customers_6(...|
|6   |    1|DBInfo       |             |dbinfo(25),dbinfo_1(26),dbinfo_2(27),dbinfo_3(28),dbinfo_4(29),dbinfo_5(30),dbinfo_6(31),dbinfo_7(32)              |
|7   |    0|E            |             |e(17),e_1(18),e_2(19),e_3(20),e_4(21),e_5(22),e_6(23),e_7(24)                                                      |
|8   |  812|HasCustomer  |[E]          |hascustomer(193),hascustomer_1(194),hascustomer_2(195),hascustomer_3(196),hascustomer_4(197),hascustomer_5(198),...|
|9   | 2484|HasEaten     |[E, HasUse...|haseaten(169),haseaten_1(170),haseaten_2(171),haseaten_3(172),haseaten_4(173),haseaten_5(174),haseaten_6(175),ha...|
|10  | 1617|HasFriend    |[E]          |hasfriend(217),hasfriend_1(218),hasfriend_2(219),hasfriend_3(220),hasfriend_4(221),hasfriend_5(222),hasfriend_6(...|
|11  |  400|HasProfile   |[E]          |hasprofile(185),hasprofile_1(186),hasprofile_2(187),hasprofile_3(188),hasprofile_4(189),hasprofile_5(190),haspro...|
|12  | 1273|HasReview    |[E]          |hasreview(201),hasreview_1(202),hasreview_2(203),hasreview_3(204),hasreview_4(205),hasreview_5(206),hasreview_6(...|
|13  | 1650|HasStayed    |[E, HasUse...|hasstayed(161),hasstayed_1(162),hasstayed_2(163),hasstayed_3(164),hasstayed_4(165),hasstayed_5(166),hasstayed_6(...|
|14  |    0|HasUsedSer...|[E]          |hasusedservice(153),hasusedservice_1(154),hasusedservice_2(155),hasusedservice_3(156),hasusedservice_4(157),hasu...|
|15  | 5104|HasVisited   |[E]          |hasvisited(177),hasvisited_1(178),hasvisited_2(179),hasvisited_3(180),hasvisited_4(181),hasvisited_5(182),hasvis...|
|16  | 1154|Hotels       |[Services, V]|hotels(65),hotels_1(66),hotels_2(67),hotels_3(68),hotels_4(69),hotels_5(70),hotels_6(71),hotels_7(72)              |
|17  |  400|IsFromCountry|[E]          |isfromcountry(145),isfromcountry_1(146),isfromcountry_2(147),isfromcountry_3(148),isfromcountry_4(149),isfromcou...|
|18  |    0|Locations    |[V]          |locations(49),locations_1(50),locations_2(51),locations_3(52),locations_4(53),locations_5(54),locations_6(55),lo...|
|19  | 1273|MadeReview   |[E]          |madereview(209),madereview_1(210),madereview_2(211),madereview_3(212),madereview_4(213),madereview_5(214),madere...|
|20  |  137|Monuments    |[V, Attrac...|monuments(89),monuments_1(90),monuments_2(91),monuments_3(92),monuments_4(93),monuments_5(94),monuments_6(95),mo...|
|21  |    0|OFunction    |             |ofunction(6)                                                                                                       |
|22  |    0|OIdentity    |             |-                                                                                                                  |
|23  |  812|Orders       |[V]          |orders(137),orders_1(138),orders_2(139),orders_3(140),orders_4(141),orders_5(142),orders_6(143),orders_7(144)      |
|24  |    0|ORestricted  |             |-                                                                                                                  |
|25  |    3|ORole        |[OIdentity]  |orole(4)                                                                                                           |
|26  |    0|OSchedule    |             |oschedule(8)                                                                                                       |
|27  |    0|OSequence    |             |osequence(7)                                                                                                       |
|28  |    0|OTriggered   |             |-                                                                                                                  |
|29  |    3|OUser        |[OIdentity]  |ouser(5)                                                                                                           |
|30  | 1000|Profiles     |[V]          |profiles(41),profiles_1(42),profiles_2(43),profiles_3(44),profiles_4(45),profiles_5(46),profiles_6(47),profiles_...|
|31  | 1951|Restaurants  |[Services, V]|restaurants(73),restaurants_1(74),restaurants_2(75),restaurants_3(76),restaurants_4(77),restaurants_5(78),restau...|
|32  | 1273|Reviews      |[V]          |reviews(129),reviews_1(130),reviews_2(131),reviews_3(132),reviews_4(133),reviews_5(134),reviews_6(135),reviews_7...|
|33  |    0|Services     |[V, Locati...|services(57),services_1(58),services_2(59),services_3(60),services_4(61),services_5(62),services_6(63),services_...|
|34  |  117|Theatres     |[V, Attrac...|theatres(105),theatres_1(106),theatres_2(107),theatres_3(108),theatres_4(109),theatres_5(110),theatres_6(111),th...|
|35  |    0|V            |             |v(9),v_1(10),v_2(11),v_3(12),v_4(13),v_5(14),v_6(15),v_7(16)                                                       |
+----+-----+-------------+-------------+-------------------------------------------------------------------------------------------------------------------+
|    |22300|TOTAL        |             |                                                                                                                   |
+----+-----+-------------+-------------+-------------------------------------------------------------------------------------------------------------------+

orientdb {db=demodb}>

Select data from a class

orientdb {db=demodb}> select * from dbinfo

+----+-----+------+------------------+-------+
|#   |@RID |@CLASS|Name              |Version|
+----+-----+------+------------------+-------+
|0   |#25:0|DBInfo|SocialTravelAgency|0.75   |
+----+-----+------+------------------+-------+

1 item(s) found. Query executed in 0.008 sec(s).
orientdb {db=demodb}>

Select all the vertices with limit

orientdb {db=demodb}> select * from V limit 35

+----+------+---------+----+----+------------------------------+---------------------------------+
|#   |@RID  |@CLASS   |Id  |Code|Name                          |in_IsFromCountry                 |
+----+------+---------+----+----+------------------------------+---------------------------------+
|0   |#33:0 |Countries|1   |AD  |Andorra                       |                                 |
|1   |#33:1 |Countries|9   |AQ  |Antarctica                    |[#146:46]                        |
|2   |#33:2 |Countries|17  |BA  |Bosnia and Herzegovina        |[#148:20]                        |
|3   |#33:3 |Countries|25  |BJ  |Benin                         |                                 |
|4   |#33:4 |Countries|33  |BT  |Bhutan                        |                                 |
|5   |#33:5 |Countries|41  |CF  |Central African Republic      |[#147:11,#151:37,#151:47]        |
|6   |#33:6 |Countries|49  |CO  |Colombia                      |[#148:4,#145:12,#150:42]         |
|7   |#33:7 |Countries|57  |DE  |Germany                       |                                 |
|8   |#33:8 |Countries|65  |EG  |Egypt                         |[#146:28]                        |
|9   |#33:9 |Countries|73  |FM  |Micronesia                    |[#146:13,#150:41]                |
|10  |#33:10|Countries|81  |GG  |Guernsey                      |[#148:38]                        |
|11  |#33:11|Countries|89  |GR  |Greece                        |[#147:23]                        |
|12  |#33:12|Countries|97  |HN  |Honduras                      |[#152:21,#149:33,#150:35,#152:45]|
|13  |#33:13|Countries|105 |IN  |India                         |[#152:20]                        |
|14  |#33:14|Countries|113 |JO  |Jordan                        |[#145:13,#151:43]                |
|15  |#33:15|Countries|121 |KP  |North Korea                   |                                 |
|16  |#33:16|Countries|129 |LI  |Liechtenstein                 |                                 |
|17  |#33:17|Countries|137 |MA  |Morocco                       |[#149:14,#145:17,#150:18]        |
|18  |#33:18|Countries|145 |ML  |Mali                          |                                 |
|19  |#33:19|Countries|153 |MT  |Malta                         |[#148:5]                         |
|20  |#33:20|Countries|161 |NC  |New Caledonia                 |[#152:10,#148:26]                |
|21  |#33:21|Countries|169 |NR  |Nauru                         |[#148:18]                        |
|22  |#33:22|Countries|177 |PH  |Philippines                   |[#152:6,#151:48]                 |
|23  |#33:23|Countries|185 |PW  |Palau                         |[#147:29,#145:37,#151:46]        |
|24  |#33:24|Countries|193 |SA  |Saudi Arabia                  |                                 |
|25  |#33:25|Countries|201 |SJ  |Svalbard and Jan Mayen Islands|[#149:3,#145:9,#148:22]          |
|26  |#33:26|Countries|209 |ST  |Sao Tome and Principe         |                                 |
|27  |#33:27|Countries|217 |TG  |Togo                          |[#152:13]                        |
|28  |#33:28|Countries|225 |TR  |Turkey                        |[#148:2,#146:49]                 |
|29  |#33:29|Countries|233 |US  |United States                 |[#145:0]                         |
|30  |#33:30|Countries|241 |VN  |Vietnam                       |[#148:3,#147:27,#152:31,#151:38] |
|31  |#33:31|Countries|249 |ZW  |Zimbabwe                      |[#147:1]                         |
|32  |#34:0 |Countries|2   |AE  |United Arab Emirates          |[#147:9]                         |
|33  |#34:1 |Countries|10  |AR  |Argentina                     |[#149:27,#148:29]                |
|34  |#34:2 |Countries|18  |BB  |Barbados                      |[#148:1,#146:6,#151:9,#148:24]   |
+----+------+---------+----+----+------------------------------+---------------------------------+

35 item(s) found. Query executed in 0.016 sec(s).
orientdb {db=demodb}>

Show data from Customers

orientdb {db=demodb}> SELECT * FROM Customers LIMIT 25

+----+-------+---------+---------+---------+---------+---------+-------------+--------------------+--------------------+--------------------+--------------------+
|#   |@RID   |@CLASS   |OrderedId|Phone    |out_HasPr|out_IsFro|in_HasCustome|out_HasStayed       |out_HasEaten        |out_MadeReview      |out_HasVisited      |
+----+-------+---------+---------+---------+---------+---------+-------------+--------------------+--------------------+--------------------+--------------------+
|0   |#121:0 |Customers|1        |+14008...|[#185:0] |[#145:0] |[#193:0]     |[#161:0]            |[#169:0,#170:0,#1...|                    |[#177:0,#178:0,#1...|
|1   |#121:1 |Customers|9        |+12322...|[#185:1] |[#145:1] |[#193:13]    |[#167:3,#168:3,#1...|[#176:8,#169:9]     |[#212:119,#210:127] |[#181:11,#182:11,...|
|2   |#121:2 |Customers|17       |+15486...|[#185:2] |[#145:2] |[#197:51]    |[#161:10,#162:10]   |[#170:17,#171:17,...|                    |[#181:25,#182:25,...|
....
....
|21  |#121:21|Customers|169      |+12999...|[#185:21]|[#145:21]|[#195:5]     |[#163:86,#164:86]   |[#171:125,#172:125] |[#214:12]           |[#181:272,#182:27...|
|22  |#121:22|Customers|177      |+16688...|[#185:22]|[#145:22]|[#194:18]    |[#165:88,#166:88,...|[#169:128,#170:12...|[#215:12,#215:32,...|[#177:280,#178:28...|
|23  |#121:23|Customers|185      |+16509...|[#185:23]|[#145:23]|[#194:31,#...|[#161:92,#162:92,...|[#169:132,#170:13...|[#216:12,#209:83,...|[#181:289,#182:28...|
|24  |#121:24|Customers|193      |+13921...|[#185:24]|[#145:24]|[#198:18]    |[#167:95,#168:95,...|[#174:138,#175:13...|[#214:3,#215:92,#...|[#177:302,#178:30...|
+----+-------+---------+---------+---------+---------+---------+-------------+--------------------+--------------------+--------------------+--------------------+

25 item(s) found. Query executed in 0.004 sec(s).
orientdb {db=demodb}>

Selecting Customer data based on record id

orientdb {db=demodb}> select * from customers where @RID =#121:16

+----+-------+---------+---------+---------+----------+-----------+----------+-------------+------------------+-------------------------------------------------+
|#   |@RID   |@CLASS   |OrderedId|Phone    |out_HasSta|out_HasProf|in_HasCust|out_IsFromCou|out_HasEaten      |out_HasVisited                                   |
+----+-------+---------+---------+---------+----------+-----------+----------+-------------+------------------+-------------------------------------------------+
|0   |#121:16|Customers|129      |+14400...|[#162:66] |[#185:16]  |[#193:4]  |[#145:16]    |[#175:95,#176:9...|[#181:209,#182:209,#183:209,#184:209,#177:210,...|
+----+-------+---------+---------+---------+----------+-----------+----------+-------------+------------------+-------------------------------------------------+

1 item(s) found. Query executed in 0.005 sec(s).
orientdb {db=demodb}>

Create local database

orientdb> create database plocal:/opt/orientdb/databases/mylearn

Creating database [plocal:/opt/orientdb/databases/mylearn] using the storage type [plocal]...
Database created successfully.

Current database is: plocal:/opt/orientdb/databases/mylearn
orientdb {db=mylearn}>

Disconnect Database

orientdb {db=mylearn}> disconnect

Disconnecting from the database [mylearn]...OK
orientdb>

Connect to Database

orientdb> connect remote:localhost/mylearn root admin

Connecting to database [remote:localhost/mylearn] with user 'root'...OK
orientdb {db=mylearn}>

Drop Database

orientdb> DROP DATABASE remote:localhost/mylearn root admin
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

Disconnecting from remote server [remote:localhost/mylearn]...
OK

Database 'remote:localhost/mylearn' deleted successfully
orientdb>

Create database mylearn with storage type: plocal; database type: graph, the default is graph. Options: graph, document

orientdb> CREATE DATABASE plocal:/opt/orientdb/databases/mylearns root admin plocal graph

Creating database [plocal:/opt/orientdb/databases/mylearns] using the storage type [plocal]...
Database created successfully.

Current database is: plocal:/opt/orientdb/databases/mylearns
orientdb {db=mylearns}>

Create database local

orientdb> CREATE DATABASE plocal:/opt/orientdb/databases/mylearn root admin

Creating database [plocal:/opt/orientdb/databases/mylearn] using the storage type [plocal]...
Database created successfully.

Current database is: plocal:/opt/orientdb/databases/mylearn
orientdb {db=mylearn}>

Create database for remote

orientdb {db=testing}> create database remote:/opt/orientdb/databases/testing1 root admin plocal graph

Creating database [remote:/opt/orientdb/databases/testing1] using the storage type [plocal]...
Disconnecting from the database [testing]...OK
Connecting to database [remote:/opt/orientdb/databases/testing1] with user 'root'...OK
Database created successfully.

Current database is: remote:/opt/orientdb/databases/testing1
orientdb {db=testing1}>

Create database testing with storage-type:plocal, db-type:graph

orientdb> create database remote:/opt/orientdb/databases/testing root admin plocal graph

Creating database [remote:/opt/orientdb/databases/testing] using the storage type [plocal]...
Connecting to database [remote:/opt/orientdb/databases/testing] with user 'root'...OK
Database created successfully.

Current database is: remote:/opt/orientdb/databases/testing
orientdb {db=testing}>

Create a class

orientdb {db=testing}> create class AGP extends V

Class created successfully.

orientdb {db=testing}>

Traverse all the field in the root record

traverse * from #16:21143

Traverse with depth

traverse * from #16:21143 while $depth <= 3 strategy BREADTH_FIRST

Show the OUT() connections for the specified hostname.

select expand(outE()) from V where host_name='KCP24LKSJFDASL9ERE9ASFKJER0940584KSJLKSJ'

Show the IN() connections for the specified hostname.

select expand(outE()) from V where host_name='KCP24LKSJFDASL9ERE9ASFKJER0940584KSJLKSJ'

Show both IN and OUT connections for the specified hostname.

select expand(bothE()) from V where host_name='KCP24LKSJFDASL9ERE9ASFKJER0940584KSJLKSJ'

Show both IN and OUT connections froma specific @RID

select expand(bothE()) from #16:21142

Traverse with depth mode

TRAVERSE both() from #23:1590 while $depth <= 1

Add existing class to super class

alter class ikwerh superclass +OTriggered

Export Database

orientdb {db=netdevices}> export database /home/krishna/netdevices.export

Importing Databases

orientdb {db=netdevices}> import database netdevice_26-dec-17.json.gz -preserveClusterIDs=true

Leave a Reply

Your email address will not be published. Required fields are marked *