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
embedded sequences, updating
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
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
 
Maarten Koopmans  
View profile  
 More options Oct 17 2012, 10:47 am
From: Maarten Koopmans <maarten.koopm...@gmail.com>
Date: Wed, 17 Oct 2012 07:47:13 -0700 (PDT)
Local: Wed, Oct 17 2012 10:47 am
Subject: embedded sequences, updating

Hi,

What's the royal road to embedding a sequence with Rogue
(a MongoJsonObjectListField in Lift) and more importantly, updating it by
adding/removing an item?

(from what I learnt on the Lift ml $push or $pull on a JValue when using
Record ~ but how to do that with Rogue in a clean way?)

Thanks!

--Maarten


 
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.
Jason Liszka  
View profile  
 More options Oct 17 2012, 11:03 am
From: Jason Liszka <jlis...@foursquare.com>
Date: Wed, 17 Oct 2012 11:03:15 -0400
Local: Wed, Oct 17 2012 11:03 am
Subject: Re: embedded sequences, updating

You can use MongoListField for lists of native types (string, int, etc), or
BsonRecordListField for lists of bson/json objects.

Some sample queries from QueryTest.scala (see TestModels.scala for record
declarations):

    // Lists
    Venue.where(_.legacyid eqs 1).modify(_.popularity setTo List(5))
 .toString() must_== query + """{ "$set" : { "popularity" : [ 5]}}""" +
suffix
    Venue.where(_.legacyid eqs 1).modify(_.popularity push 5)
.toString() must_== query + """{ "$push" : { "popularity" : 5}}""" + suffix
    Venue.where(_.legacyid eqs 1).modify(_.tags pushAll List("a", "b"))
.toString() must_== query + """{ "$pushAll" : { "tags" : [ "a" , "b"]}}"""
+ suffix
    Venue.where(_.legacyid eqs 1).modify(_.tags addToSet "a")
.toString() must_== query + """{ "$addToSet" : { "tags" : "a"}}""" + suffix
    Venue.where(_.legacyid eqs 1).modify(_.popularity addToSet List(1L,
2L)).toString() must_== query + """{ "$addToSet" : { "popularity" : {
"$each" : [ 1 , 2]}}}""" + suffix
    Venue.where(_.legacyid eqs 1).modify(_.tags popFirst)
.toString() must_== query + """{ "$pop" : { "tags" : -1}}""" + suffix
    Venue.where(_.legacyid eqs 1).modify(_.tags popLast)
 .toString() must_== query + """{ "$pop" : { "tags" : 1}}""" + suffix
    Venue.where(_.legacyid eqs 1).modify(_.tags pull "a")
.toString() must_== query + """{ "$pull" : { "tags" : "a"}}""" + suffix
    Venue.where(_.legacyid eqs 1).modify(_.popularity pullAll List(2L, 3L))
.toString() must_== query + """{ "$pullAll" : { "popularity" : [ 2 ,
3]}}""" + suffix
    Venue.where(_.legacyid eqs 1).modify(_.popularity at 0 inc 1)
.toString() must_== query + """{ "$inc" : { "popularity.0" : 1}}""" + suffix
    // alternative syntax
    Venue.where(_.legacyid eqs 1).modify(_.popularity idx 0 inc 1)
 .toString() must_== query + """{ "$inc" : { "popularity.0" : 1}}""" +
suffix

    // BsonRecordField subfield queries
    Venue.where(_.claims.subfield(_.status) contains
ClaimStatus.approved).toString() must_== """db.venues.find({
"claims.status" : "Approved"})"""
    Venue.where(_.lastClaim.subfield(_.userid) eqs 123)
 .toString()      must_== """db.venues.find({ "lastClaim.uid" : 123})"""
    Venue.where(_.claims.subfield(_.source.subfield(_.name)) contains
"twitter").toString() must_== """db.venues.find({ "claims.source.name" :
"twitter"})"""

    // select subfields
    Tip.where(_.legacyid eqs 1).select(_.counts at "foo").toString()
must_== """db.tips.find({ "legid" : 1}, { "counts.foo" : 1})"""
    Venue.where(_.legacyid eqs
1).select(_.geolatlng.unsafeField[Double]("lat")).toString() must_==
"""db.venues.find({ "legid" : 1}, { "latlng.lat" : 1})"""
    Venue.where(_.legacyid eqs
1).select(_.lastClaim.subselect(_.status)).toString() must_==
"""db.venues.find({ "legid" : 1}, { "lastClaim.status" : 1})"""
    Venue.where(_.legacyid eqs
1).select(_.claims.subselect(_.userid)).toString() must_==
"""db.venues.find({ "legid" : 1}, { "claims.uid" : 1})"""

On Wed, Oct 17, 2012 at 10:47 AM, Maarten Koopmans <


 
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.
End of messages
« Back to Discussions « Newer topic     Older topic »