Get the name of a BsonRecord and setFromString

13 views
Skip to first unread message

Riccardo Sirigu

unread,
Feb 7, 2017, 11:35:18 AM2/7/17
to Lift
Hi guys,

I have this model 

class MultilingualName extends BsonRecord[MultilingualName]{
 
override def meta: BsonMetaRecord[MultilingualName] = MultilingualName

 
object it extends StringField(this, 80)
 
object de extends StringField(this, 80)
 
object fr extends StringField(this, 80)
 
object en extends StringField(this, 80)
}

object MultilingualName extends MultilingualName with BsonMetaRecord[MultilingualName]

class Poi extends MongoRecord[Poi] with ObjectIdPk[Poi]{
 
override def meta: MongoMetaRecord[Poi] = Poi

 
object name extends BsonRecordField(this, MultilingualName)
 
.....
}


I have to import a CSV file and with a select I can choose on wich field to store a given column of the CSV file.

For example 

poi.fieldByName("city").map(f => f.setFromString("Rome"))

The problem is that with embedded documents, such as name in the example, I can't get the name that I want.

I would like to have something like "name.it"  but I get only "name"

The same is true if I try to do fieldByName("name.it")

How can I do that? 



Tim Nelson

unread,
Feb 8, 2017, 5:36:25 AM2/8/17
to Lift
Hi Riccardo,

In short, you can't. "name" is the field. You would have to set the whole BsonRecord, there's no way to get individual fields on the BsonRecord.

Can you access multiple columns in the csv at the same time? If so, you should be able to do something like:

   
val rec = MultilingualName.createRecord
 
.it("Riccardo")
 
.en("Richard")


poi
.fieldByName("name").map(f => f.set(rec))


Tim

Riccardo Sirigu

unread,
Feb 8, 2017, 11:40:48 AM2/8/17
to Lift
Thank you Tim,

I'll try with that
Reply all
Reply to author
Forward
0 new messages