Moving from MongoDB to OrientDB - Architecture

743 views
Skip to first unread message

Mitul Golakiya

unread,
Mar 6, 2014, 1:42:40 PM3/6/14
to orient-...@googlegroups.com
Hello All,

I am new to OrientDB and we want to move from MongoDB to OrientDB. Because at this stage we have very complex requirements of joins between tables(means our modules) and also we are facing huge problem of memory consumption.

We have a different modules into our system like persons, leads, support_cases. And these all modules are internally connected. So in MongoDB we can not perform a join between them to retrieve data with some complex relationships. So we want to give a try to OrientDB, if its fit well to our requirements.

We have one person module and we are storing full object of person into MongoDB. Person can have multiple phones, emails & addresses and other custom fields.

Here is the structure that we have currently in MongoDB:

{
personId: 'personId1',
fname: 'Mitul',
lname: 'Golakiya',
phnoes: [
{ phoneId: 'phoneId1', phone: '9999999999' },
{ phoneId: 'phoneId2', phone: '9999999900' }],
emails: [
{emailId:'emailId1', email: 'm...@mitul.me'}
],
addresses: []
}

We have embedded array for all because we want to retrieve all the fields when we want person object and also whole person object is passed via services while insertion of person.
And also we have a requirement like, we have to update single phone, email & address object.

So to update single object in OrientDB we have to take separate tables for email, phone & address.

So now my problem is, I have to insert all the things separately and create a links between them.

Here is my schema:

In person I am creating three fields emails, phones & addresses with LINKSET (@rid) type with its relevant linked classes.
And in email, phone & address table, I am saving LINK type field which contains personId (@rid).

So I am performing following sequence for insertion of person.

1. First I have to insert person.
2. Then insert email with person.@rid.
3. Insert phones with person.@rid.
4. Insert address with person.@rid.
5. Now update person's table and insert a @rids of email, phone & address in LINKSET field.

So it is taking too much time in insert as compared to mongo.
Mongo is taking only 140-150 millisecond. And in OrientDB these five operations are taking more than 1 second.

So is there any way by which I can make it fast or I can insert it in a single query with all LINKs ??
Or any other way by which I can optimize the time by schema change or anything else.

Thanks in advance.

Ameer Tamboli

unread,
Mar 7, 2014, 4:17:08 AM3/7/14
to orient-...@googlegroups.com
Hi Mitul,

I think you should have something like this:

create class Phone extends V;
create property Phone.phoneId STRING;
create property Phone.phone STRING;

create class Email extends V;
create property Email.emailId STRING;
create property Email.email STRING;

create class Address extends V;
create class Address.line1 STRING;
create class Address.line2 STRING;
create class Address.city STRING;
create class Address.zipcode STRING;

create class Person extends V;
create property Person.personId STRING;
create property Person.fname STRING;
create property Person.lname STRING;
create property Person.phones LINKLIST Phone;
create property Person.emails LINKLIST Email;
create property Person.addresses LINKLIST Address;


It seems you are trying to link Person to Email and back from Email to Person. I guess one way relation should be more than enough. But I might be wrong if you have different query requirements.

Regards,
Ameer




--

---
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/groups/opt_out.

Andrey Lomakin

unread,
Mar 7, 2014, 6:54:18 AM3/7/14
to orient-database
Hi,
You do not need to insert them as separate insertions.
Just create all objects at once and store root document everything will be stored and links will be updated automatically.

Also with what kind of database do  you work graph of document ?
if you use document database usage of LINKSET is OK.

If you work with graph database you should connect vertexes through edges.
Also you should do it in single tx to avoid data consistency problems in case if you will have errors during insertions.

Our users report that insertion speed is at least 1500 rec/s (2/3 ms for single record) so insertion of 5 records for a second (it should be about 5 ms for such small amount of data) is indication that something is really wrong.
Could you send me example of database and code which you use to import data ? 

--
Best regards,
Andrey Lomakin.

Orient Technologies
the Company behind OrientDB

Gaurav Dhiman

unread,
Mar 7, 2014, 8:29:49 AM3/7/14
to orient-...@googlegroups.com


On Friday, March 7, 2014 5:24:18 PM UTC+5:30, Andrey Lomakin wrote:
Hi,
You do not need to insert them as separate insertions.
Just create all objects at once and store root document everything will be stored and links will be updated automatically.

Lovely ... good to know this thing that all links are created automatically and we just need to do single insert.
An example insert statement on given schema will help understand better.

 

Andrey Lomakin

unread,
Mar 7, 2014, 9:06:05 AM3/7/14
to orient-database
It is possible,
But you did not answer which kind of database do you use graph or document ?


--

---
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.

Gaurav Dhiman

unread,
Mar 7, 2014, 9:13:35 AM3/7/14
to orient-...@googlegroups.com
Andrey,

I am not the original author of this thread :-). Well in my case I am using document type DB.
It will be good if you can give example in both cases of document and graph DBs.

Regards,
Gaurav


--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/jUCf8SQg0jI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.

Mitul Golakiya

unread,
Mar 7, 2014, 10:58:01 AM3/7/14
to orient-...@googlegroups.com
We are using Document Type database.

I had sent one mail with my current schema of MongoDB and OrientDB to your external gmail email address which I got from Github.

Please check and can you suggest how can I do that ??

On Friday, March 7, 2014 5:24:18 PM UTC+5:30, Andrey Lomakin wrote:

Gaurav Dhiman

unread,
Mar 9, 2014, 2:32:18 PM3/9/14
to orient-...@googlegroups.com
Andray, can you suggest how to do multiple inserts / updates in single SQL, considering the case of document DB that Mitul Golakiya presented.
It will help me and other members on community to best utilize the power of OrientDB.

Regards,
Gaurav

Luca Garulli

unread,
Mar 9, 2014, 10:58:57 PM3/9/14
to orient-database
Hi Gaurav,
you could group inserts in one call like this:

insert into xxx (x,y) values (1,2) (2,3) (3,4)

This will insert 3 records.

Lvc@



Message has been deleted

Mitul Golakiya

unread,
Mar 10, 2014, 12:49:37 AM3/10/14
to orient-...@googlegroups.com
That works if we want to insert records in single table, but what about if we want to insert records in different table with relationships ??
Like in my case, I want person object in person table, emails in emails table, phones in phones table and I had relationships between them.

So How can I do that with in Query ??

Gaurav Dhiman

unread,
Mar 11, 2014, 2:51:24 AM3/11/14
to orient-...@googlegroups.com
@Andrey / @Luca,

Can you help here ?

How to do multiple inserts / updates across multiple connected classes in single statement ?

For instance, lets take a simple example of three classes employer, employee and contact
  • employer attributes - company_name (string), employees (Linkset to employee class), contact_details (Linkset to contact class)
  • employee attributes - name (string), employer (Link to employer class), contact_details (Linkset to contact class)
  • contact attributes - email_id (string), contact_of (Link to employee or employer class)

How can we perform insert across all three classes and establish inter-linking in single insert / update statement ?

Regards,
Gaurav

Luca Garulli

unread,
Mar 11, 2014, 7:48:33 AM3/11/14
to orient-database
Hi,
you could use sub-query, like:

insert into a set b = (insert into c set d = 44)

Lvc@

Gaurav Dhiman

unread,
Mar 19, 2014, 1:43:31 AM3/19/14
to orient-...@googlegroups.com


On Friday, March 7, 2014 5:24:18 PM UTC+5:30, Andrey Lomakin wrote:
Hi,
You do not need to insert them as separate insertions.
Just create all objects at once and store root document everything will be stored and links will be updated automatically.


Hi Andrey,

Can you explain above statements more with an example ?

Lets say, there are three classes:
Person, Emails, Phones

with below two way linking in Document based DB
Person (1) <----> Emails (N)
Person (1) <----> Phones (N)

Person.emails is linkset to records in Emails class
Emails.person is link to record in Person class

Person.phones is linkset to records in Phones class
Phones.person is link to record in Person class


Given above situation, what is the best way to insert these documents with all inter-linking done. Performance and consistency are both important to consider.

I will appreciate if you can give one example code.

Regards,
Gaurav

Luca Garulli

unread,
Mar 19, 2014, 1:45:16 AM3/19/14
to orient-database
Hi Guarav,
you've a bidirectional relationship, so the easiest way is using Graph API.

Lvc@



--

Gaurav Dhiman

unread,
Mar 19, 2014, 1:59:07 AM3/19/14
to orient-...@googlegroups.com
@Luca,

What is Graph API ? Just to clear, I am not using JAVA. My stack is Backend is OrientDB + OrientDB functions (in JS) and Frontend is Angular + BootStrap -- NO JAVA

I decided to use document type DB over graphd type DB after looking at below PPT

Even though I am using document type DB, I want to maintain two way links. Can you give one example of interlinking inserts in my given case ?

Another related question:
If I delete one link (from Person to Emails), will the reverse link will also get deleted automatically (Emails to Person) OR I need to remove that manually ?

Regards,
Gaurav

Luca Garulli

unread,
Mar 19, 2014, 2:04:10 AM3/19/14
to orient-database
On 19 March 2014 06:59, Gaurav Dhiman <gau...@techzulla.com> wrote:
@Luca,

Hi Gaurav,
 

What is Graph API ? Just to clear, I am not using JAVA. My stack is Backend is OrientDB + OrientDB functions (in JS) and Frontend is Angular + BootStrap -- NO JAVA

You can call Java even from OrientDB Server Side function ;-) But you can use the Graph API even from SQL. Look at the tutorial: https://github.com/orientechnologies/orientdb/wiki/Tutorial%3A-working-with-graphs
 
I decided to use document type DB over graphd type DB after looking at below PPT

Even though I am using document type DB, I want to maintain two way links. Can you give one example of interlinking inserts in my given case ?

Another related question:
If I delete one link (from Person to Emails), will the reverse link will also get deleted automatically (Emails to Person) OR I need to remove that manually ?

If you use the graph model all the links are always coherent when you delete edges, while with document API it's on your charge.

Lvc@
Reply all
Reply to author
Forward
0 new messages