Search code examples
mongodbplayframeworkyamlmorphia

How to load embedded data with YAML into play/morphia/mongodb?


I'm developing a web app using the play! framework and morphia/mongodb. I'm trying to load some initial data with the YAML feature provided by play.

I can't figure out the correct syntax for importing embedded objects.

Here is my data model using the morphia mongodb mapper:

@Entity(noClassnameStored=true)
public class MongoEvent extends Model {

public String eventId;
public String name;

@Embedded
public static List<MongoEventListItem> eventListItems;

public MongoEvent(String name){
    UUID uuid = UUID.randomUUID();
    eventId = uuid.toString();
    this.name = name;
    }
}

@Embedded
public class MongoEventListItem {

    public String name;
    public String quantity; 
}

Using the follwoing yaml code I can import the MongoEvent but not the embbeded MongoEventListItem:

MongoEventListItem(mitem2):
 name: beer
 quantity: 50

MongoEvent(mevent1):
 eventId: 4
 name: mango_event
 eventListItems: [mitem2]

In mongodb I get the following data:

{ "_id" : ObjectId("4f167231c2e6ac08b5c86685"), 
  "eventId" : "4", 
  "name" : "mango_event", 
  "date" : ISODate("2012-06-09T00:00:00Z") }

Any ideas about the correct YAML syntax?

thanks


Solution

  • Loading embedded Object list is not supported at current PlayMorphia module (v1.2.4). Check https://github.com/greenlaw110/play-morphia/issues/28.