Am 17.04.2014 um 15:05 schrieb olivier auverlot <[email protected]>:
> 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.
Norbert
> Olivier ;-)
>
>
> 2014-04-17 14:10 GMT+02:00 Norbert Hartl <[email protected]>:
>
> Am 17.04.2014 um 13:53 schrieb olivier <[email protected]>:
>
> > 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
>
>
>