Abey
Abey

Reputation: 1428

Find query MongoDB using CakePHP

The following is the json array I have in a collection called claims in MongoDB.

 {
  "xmllisting_id": "537f371fb2e380922fff0e2c",
  "pharmacyfiles_id": "537f3402b2e380732aa6032d",
  "claim": {
    "MemberID": "097110330047532601",
    "PatientShare": "0",
  },
  "modified": ISODate("2014-05-23T13:12:17.191Z"),
  "created": ISODate("2014-05-23T13:12:17.192Z")
}

I need to find all claims with a specified MemberID.I have tried the following in CakePHP without any success.

$claims = $claimobj->find(
   'all',
   array(
       'conditions' => array( 
           'claim' => array('MemberID' =>  '097110330047532601') 
       )
   )
);

How can I do it?

Upvotes: 0

Views: 276

Answers (1)

Blakes Seven
Blakes Seven

Reputation: 50406

Finding "nested" details in MongoDB usually requires "dot notation". Otherwise you are actually asking for an object that has "exactly" the key and "only" the key you are specifying to match. Which of course it does not, as there is more information there:

$claims = $claimobj->find(
    'all',
     array(
         'conditions' => array(
             'claim.MemberID' => '097110330047532601'
         )
    )
);

So the path is "claim.MemberID" and not 'claim' => array('MemberID' => '097110330047532601' ) as you have written.

Upvotes: 2

Related Questions