Skip to content

Instantly share code, notes, and snippets.

@EchoAbstract
Created February 28, 2012 03:54
Show Gist options
  • Save EchoAbstract/1929282 to your computer and use it in GitHub Desktop.
Save EchoAbstract/1929282 to your computer and use it in GitHub Desktop.
Many-to-Many REST
// Find all Dr's named Joe at Mercy Hospital
GET /appdata/[appKey]/doctors/?query={"firstName": "Joe", "hospital": "Mercy"}
[{"_id": "998798ad987fe987e987bc98766",
"firstName": "Joe",
"lastName": "Brown",
"hospital": "Mercy",
"speciality": "oncology"},
{"_id": "ca6775feba86554",
"firstName": "Joe",
"lastName": "Baker",
"hospital": "Mercy",
"speciality": "internal medicine"}]
// Find all patients seen by Dr. Joe Brown
GET /appdata/[appKey]/patients/?query={"doctors":"998798ad987fe987e987bc98766"}
[{"_id": "001",
"firstName": "Waldo",
"lastName": "Bond",
"doctors": ["998798ad987fe987e987bc98766", "98698ad989d987f9987e"],
"history": "..."},
{"_id": "002",
"firstName": "Keith",
"lastName": "Emerson",
"doctors": ["998798ad987fe987e987bc98766", "82888277266ffaacafe", "ca6775feba86554"],
"history": "..."}]
// Find Waldo's other Doctor
GET /appdata/[appKey]/doctors/98698ad989d987f9987e
{"_id": "98698ad989d987f9987e",
"firstName": "Mary",
"lastName": "Ng",
"hospital": "Tufts Medical Center",
"speciality": "internal medicine"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment