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 7309007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:39:13+00:00 2026-05-28T23:39:13+00:00

I have three objects case class Metric(val name: String, val tags: Map[String, String]) case

  • 0

I have three objects

case class Metric(val name: String, val tags: Map[String, String]) 

case class Threshold(val metric: Metric, val critical: Long, val warning: Long)

class Profile(val name: String, val thresholds: List[Threshold])

I plan to store only the Profile object in Mongo DB, but in the Scala App they should be represented by their types.

I am using Subset for the same and have defined of the following nature

implicit val reader = ValueReader[Threshold]({
case metric(metric) ~ critical(critical) ~ warning(warning) =>
  new Threshold(metric, critical, warning)
})
implicit val writer = {
def f(threshold: Threshold): DBObject =
  (metric -> threshold.metric) ~ (critical -> threshold.critical) ~ (warning -> threshold.warning)
ValueWriter(f _)
} 

How can I query to and from Mongo Now?
Any examples around this?

  • 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-28T23:39:14+00:00Added an answer on May 28, 2026 at 11:39 pm

    Integration test is a good example on how to work with nested object, query, update etc. Parts of this test are scattered across the documentation as well.

    If you plan to read from Mongo, you need readers for all the parts of your model. If you plan to query or update, you need writers as well. Scala compiler should issue an error if it cannot find a necessary implicit.

    How would you query Profiles:

    object Profile {
      val name = "name".fieldOf[String]
      val thresholds = "thresholds".subset(Threshold).of[List[Threshold]]
    
      // typical query:
      def alarmsFor(metric: String) =
        collection.find( thresholds elemMatch {t =>
          t.metric.where{_.name == metric} && t.critical > 10
        } ) map {
          case name(n) ~ thresholds(t) => new Profile(n, t)
        }
    }
    

    I’ve made a couple of assumptions in this snippet:

    • Threshold‘s fields are defined in object Threshold (t is where you get it)
    • Threshold.metric field is a subset itself, e.g. val metric = "metric".subset(Metric).of[Metric], so that you can query metric.where{_.name == metric}

    Note that as of version 0.7.0 there is still no reader/writer for Map[String,T] (though I plan to have it eventually) — you’ll have to develop it (if you need this field) or work around this problem in Metric‘s reader/writer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataTemplate that is displaying objects with three fields, e.g.: Name =
Basically I have some class objects, each with three properties. Once one class object
Basically, I want to have a Map indexed by type objects. In this case,
In my application, I have three collection objects which store data. The data which
I have three ObservableCollections: CharacterCollection, LocationCollection, and ItemCollection. They are all collections of objects;
We have a three-tier architecture consisting of Classic ASP Frontend, VB COM+ Objects and
I have a function that receives three different people objects and generates a new
I have three pages: Login.aspx, Index.aspx and a C# class file named GlobalData.cs The
Let me have two very basic objects like: public class View { public View(Controller
In my case I have 2D ArrayList full of objects that have data which

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.