Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7407005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:38:35+00:00 2026-05-29T05:38:35+00:00

I need the User class to contain a map of strings and I saw

  • 0

I need the User class to contain a map of strings and I saw MongoMapField in the api so I used it because it seemed appropriate. Here’s my code:

class User private () extends ProtoAuthUser[User] with ObjectIdPk[User] {
  def meta = User

  object oauth extends MongoMapField[String, String]("") {
    def setToken(provider: String, token: String) {this.value += (provider -> token) }
    def getToken(value: String) = { 
      if(!this.value.isEmpty) Full(this.value.get(value) match {
        case Some(value) => value
        case None => ""
      })
      else Empty
    }
  }
}

setToken in this case doesn’t work because MongoMapField is immutable (from my assumption) and the following code doesn’t work either:

def setToken(provider: String, token: String) { this.value = this.value + (provider -> token) }

Does anyone know what is the best way to create/update a map of strings in mongo that is also attached to the user?

Thanks =)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:38:36+00:00Added an answer on May 29, 2026 at 5:38 am

    When dealing with immutable data structures, you need to think in terms of replacing the existing value with a new value instead of trying to modify the existing value.

    So, to get your code to work, you would need to change it to:

    class User private () extends ProtoAuthUser[User] with ObjectIdPk[User] {
      def meta = User
    
      object oauth extends MongoMapField[String, String](this) {
        def setToken(provider: String, token: String) {
          this.set(this.value + (provider -> token))
        }
        def getToken(value: String): Box[String] = { 
          Box(this.value.get(value))
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two user controls that need to add a class atribute to the
I need a php validator class that validates user inputs. I want it to
I need user to define all the environment variables needed for my program in
I need the user to enter a URL within my form. However, URL is
I need the user to be able to upload multiple files to my server,
I need to implement a view where I need the user to answer several
i have a text field in Contact screen and the user need to enter
I need to work with decimals. In my program, the user need to put
My point is this. For test i need when user check chk1 the chk2
I have a simple table view which is editable. All I need the user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.