tulipemoutarde.be

Software Developer

Smalltalk, Swift, Java, Obj-C

@fstephany | Email | LinkedIn

I'm currently working at Ta Mère SCRL a small development shop in Belgium.

We mainly do mobile apps (iOS, Android) for clients. We also have a strong interest in Pharo Smalltalk and Rust.

logo Ta Mère SCRL

Misc stuff about Voyage and MongoDB

28 May 2012 in mongoDB pharo smalltalk voyage 

Esteban replied to my first post about Voyage. Unfortunately, my blog provider messed up when formatting the comment. Here’s a summary of his remarks:

Magritte

Magritte is not necessary for the basic scenarios. Voyage is smart enough to infer the types of your instance variables and can serialize them. You don’t need to describe everything like you would do when building an UI with Magritte.

The Magritte descriptions are only needed when you want to override the defaults of want to have a one-to-many relationships.

In the future, it will be able to infer the to-many relations automatically but at the moment you still have to tell voyage how to deal with them.

^VOMongoToManyDescription new
    attributeName: 'myInstVar'; "Acts on this inst var"
    kindCollection: Set; "Set instead an OrderedCollection"
    beLazy; "I want that references to be retrieved lazily"
    yourself.

Browse VOMongoRelationDescription and its subclasses to see what is possible.

Embedded documents

As we’ve seen previously, it is pretty easy to map a relation. In our example, we declared both MQSpaceship and MQPilot as persistent by implementing isPersistent on the class side.

This isPersistent method has an unfortunate name. It actually means that a collection with the name of the class will be created in the database. If we hadn’t declared MQPilot persistent, it would have been completely embedded in the spaceship.

Ignore instance variable

Sometimes you do not want to serialize all your instance variables. In such cases, add a VOMongoTransientDescription like this:

mongoTransientDescription

  ^VOMongoTransientDescription new
    attributeName: 'puppies';
    yourself.

Now, the puppies instance variable will be ignored by the serializer and won’t be stored in Mongo.

That’s all for today. Once again, huge thanks to Esteban for this super nice library!