MongoDB, Grails and Relationships

I was wondering how the MongoDB plugin for Grails will handle relationships. To test this, I made a very simple application with two domain classes:

Authorhave two fields: String firstNameandString lastName

Bookhave two fields: String titleandAuthor author

After you configure MongoDB Grails and I made a few Authorand Bookand looked into the MongoDB interactive shell. I found that relations are processed in the same way as they will be processed in a relational database: links to id fields of other objects.

So now for the questions:

  • For GORM to pull this out, does a separate connection is required to retrieve each document?
  • If so, is this not better in a relational database like PostgreSQL or MySQL?
  • If the answer to the above two questions is really yes, then is there a better way to manage relationships in a document database such as MongoDB? I understand that MongoDB should not be relational, but there are some things that I donโ€™t see how to get around relationships without duplicating data (thereby doing nightmares updates).

Edit: I also noticed that grails is not sorting correctly by id property for my authors. Is this related to using MongoDB? In the shell, I see that the _id property of all documents made by Grails is data type NumberLong.

+5
source share
2 answers

, MongoDB , , , .

. MongoDB , .

- . , .

, (N: 1), , " " . , . ? - . , .

, (M: N), .

, MongoDB " ", , MongoDB .

, grails "id" ...

Grails. , "" ObjectIds ( MongoID). , .

+3

id , ObjectId id String id , GORM . , .

+1

All Articles