Get _id from MongoDB using Scala

Posted by user2438383 on Stack Overflow See other posts from Stack Overflow or by user2438383
Published on 2013-10-31T12:46:03Z Indexed on 2013/11/12 21:54 UTC
Read the original article Hit count: 146

Filed under:
|
|

For a given JSON how do I get the _id to use it as an id for inserting in another JSON?

Tried to get the ID as shown below but does not return correct results.

private def getModelRunId(): List[String] = {
  val resultsCursor: List[DBObject] =
    modelRunResultsCollection.find(MongoDBObject.empty, MongoDBObject(FIELD_ID -> 1)).toList
  println("resultsCursor >>>>>>>>>>>>>>>>>> " +  resultsCursor)
  resultsCursor.map(x => (Json.parse(x.toString()) \ FIELD_ID).asOpt[String]).flatten
}
{
"_id": ObjectId("5269723bd516ec3a69f3639e"),
"modelRunId": ObjectId("5269723ad516ec3a69f3639d"),
"results": [
{
  "ClaimId": "526971f5b5b8b9148404623a",
  "pricingResult": {
    "TxId": 0,
    "ClaimId": "Large_Batch_1",
    "Errors": [

    ],
    "Disposition": [
      {
        "GroupId": 1,
        "PriceAmt": 20,
        "Status": "Priced Successfully",
        "ReasonCode": 0,
        "Reason": "RmbModel(PAM_DC_1):ProgramNode(Validation CPG):ServiceGroupNode(Medical Services):RmbTerm(RT)",
        "PricingMethodologyId": 2,
        "Lines": [
          {
            "Id": 1
          }
        ]
      }
    ]
  }
},

© Stack Overflow or respective owner

Related posts about JSON

Related posts about mongodb