Hi,

This morning, I arrived early at office because I was impatient to test the proposed solutions. Thank for your help, my problem is solved and I understand better the usage of Voyage and Mongo.

We learn something each day and it's cool !

Best regards
Olivier ;-)��


2014-04-17 21:56 GMT+02:00 pharo4Stef@free.fr <pharo4Stef@free.fr>:
esteban

you should do a pass on the voyage documentation chapter and add this kind of infomration.
We can pair write if you want.

stef


On 17/4/14 17:56, Esteban Lorenzano wrote:

On 17 Apr 2014, at 15:18, Norbert Hartl <norbert@hartl.name> wrote:


Am 17.04.2014 um 15:05 schrieb olivier auverlot <olivier.auverlot@gmail.com>:

thanks Robert for the explications.

It���s Norbert btw. :)

I agree with you that's the best way to remove a book is to delete the reference in ��ComicsCollection.

But how to do that ? Must I simply remove the reference in the ordered collection ? Voyage will syncronize automatically the data in memory with the content of the database ? Must I force the save of the data after removing the reference ?

You need to explicitly save it as we don���t have something like write barriers in the image. So

aComicCollection��
removeBook: aBook;
save

is needed.

yes, and also (if you want to be clean):

aBook remove.��

(assuming aBook is also persistent).��

But as Sabina points: #enableMissingContent in CommicCollection will help you to simplify things, then you just need: "aBook remove", and next time you read aComicCollection it will ���clean��� the invalid reference.��
I call that ���eventual integrity��� :P��
but beware of it��� is considered ���power voyage programming��� :)

Esteban


Norbert

Olivier ;-)


2014-04-17 14:10 GMT+02:00 Norbert Hartl <norbert@hartl.name>:

Am 17.04.2014 um 13:53 schrieb olivier <olivier.auverlot@gmail.com>:

> Hi,
>
> I'm using Voyage in a Pharo application.
>
> I have two MongoDB collections which are ComicsCollection and ComicsBook. Each book is attached to a instance of ComicsCollection. The reference of each book is stored in an ordered collection (in the instance of ComicsCollection). The problem is that if I remove a book, the reference to the book is not deleted from ComicsCollection.
>
> How can I remove properly a book and the reference to the book ?
>
From the smalltalk image view the problem is usually exactly the opposite: You don���t delete objects but you remove references to them. As voyage maps objects it is a good idea to stay in the object realm. So you should rather remove the book from the collection. This way you won���t get errors just garbage. The ���real��� problem that arises then is that the book would still be in the database. Just like it is in the image but there is no garbage collector for mongo. To decide that from the image is not possible. You load only a sub graph from the database into image memory. So you don���t know if there are other objects referencing the book.

If your records fit all in memory you could load all collections and books and build the difference between all referenced books in the collections and the total amount of books. The difference will be the set of objects not being referenced by a collection and those can be deleted.

If the records do not fit in memory an alternative strategy would be needed. I started to research if it is possible to build a map/reduce based garbage collector for common cases but got distracted. But I have the same problem so I will need to pick it up some time.

hope that helps,

Norbert