Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Updating an embedded document (MongoJsonObjectField)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Tim Nelson  
View profile  
 More options Oct 15 2012, 3:47 pm
From: Tim Nelson <tnell...@gmail.com>
Date: Mon, 15 Oct 2012 12:47:29 -0700 (PDT)
Local: Mon, Oct 15 2012 3:47 pm
Subject: Re: [Lift] Re: Updating an embedded document (MongoJsonObjectField)

Hi Maarten,

If you have the following:

case class TypeTestJsonObject(
  intField: Int,
  stringField: String
) extends JsonObject[TypeTestJsonObject]
{
  def meta = TypeTestJsonObject

}

object TypeTestJsonObject extends JsonObjectMeta[TypeTestJsonObject]

class ListTestRecord private () extends MongoRecord[ListTestRecord] with
UUIDPk[ListTestRecord] {
  def meta = ListTestRecord

  object mandatoryMongoJsonObjectListField extends
MongoJsonObjectListField(this, TypeTestJsonObject)

}

object ListTestRecord extends ListTestRecord with
MongoMetaRecord[ListTestRecord]

To add an item to the field:

import net.liftweb.json._
import net.liftweb.json.JsonDSL._

val rec = ListTestRecord.find(...)
val newObj = TypeTestJsonObject(1, "a")

val qry: JValue = ("_id" -> ....)
val upd: JValue = ("$push" -> ("mandatoryMongoJsonObjectListField" ->
newObj.asJObject))

rec.update(qry, upd)

To remove an item:

val upd: JValue = ("$pull" -> ("mandatoryMongoJsonObjectListField" ->
newObj.asJObject))

rec.update(qry, upd)

I've been thinking of adding these functions to the ListFields but haven't
gotten around to it.

Rogue has a much better way of doing this, btw. If you haven't looked into
that, I highly recommend it. Not sure if MongoJsonObjectListField is
supported, though.

Tim

On Monday, October 15, 2012 9:34:34 AM UTC-5, maarten wrote:

> Hi Tim,

> I have trouble seeing how that works (nor could I find an example)
> from Record. Or should I code that query directly as a string (in
> which case I have trouble seeing how that translates/serializes to
> MongoJsonObjectField[MyClass])?

> Thanks,

> Maarten

> On Mon, Oct 15, 2012 at 3:06 PM, Tim Nelson <tnel...@gmail.com<javascript:>>
> wrote:
> > Hi Maarten,

> > If all you're updating is the one column, I would say use an update
> > statement.

> > Tim

> > On Monday, October 15, 2012 4:46:03 AM UTC-5, maarten wrote:

> >> Hi,

> >> Subjects says it hopefully all: what is the most elegant way to update
> >> (i.e. add/remove items to/from) a MongoJsonObjectField?

> >> I only found solutions that force you to build new lists on the client
> >> side - which I hoped to avoid. Because that would be quite dangerous
> >> wrt locking etc (concurrent updates).

> >> Any feedback appreciated - and I'll add it to the Wiki as soon as I
> >> figure it out.

> >> Thanks!

> >> --Maarten

> > --
> > --
> > Lift, the simply functional web framework: http://liftweb.net
> > Code: http://github.com/lift
> > Discussion: http://groups.google.com/group/liftweb
> > Stuck? Help us help you:
> > https://www.assembla.com/wiki/show/liftweb/Posting_example_code


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.