Skip to content

Instantly share code, notes, and snippets.

@almost
Created February 22, 2012 12:16
Show Gist options
  • Save almost/1884579 to your computer and use it in GitHub Desktop.
Save almost/1884579 to your computer and use it in GitHub Desktop.
CouchDB: M2M link via non-primary keys.
// I have meetings like this:
{
"type": "meeting"
"_id": "MEETINGID",
"emails": ["[email protected]", "[email protected]"]
// Lots of others things
}
// I have users like this:
{
"type": "user",
"_id": "USERID",
"emails": ["[email protected]", "[email protected]"]
}
// I need to keep them linked via email. But I can definitely split out the emails into separate documents if that helps.
// I need to be able to lookup all users for a meeting and all meetings for a user. I can see lots of ways to lookup meetings by email and users by email, but that's as far as I get. All the solutions I can think of require multi-level map-reduce which wouldn't work with couch.
// I'm looking for a view that produces this:
{
"key": "MEETING",
"document": {/* user */}
}
// And one that does the inverse:
{
"key": "USERID",
"document": {/* meeting */}
}
// Ideas would be very welcome! :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment