I have a video-game themed Six Degrees of Separation app and I want to know the best way to implement breadth-first search using node.js and MongoDB.
My app uses https://github.com/mongodb/node-mongodb-native for MongoDB.
For the collection that I'm using, my documents look like this:
{
_id: "Mega Man",
with: [
{ _id: "Wolverine", in: "Marvel vs. Capcom"},
{ _id: "Snake Man", in: "Mega Man's Soccer"}
]
}
If I want the characters related to Mega Man, I'd need a query to produce
[
{ _id: "Wolverine", with: [...]},
{ _id: "Snake Man", with: [...]}
]
So:
What query/queries would I use to get a list of characters, each one with an _id corresponding to the _ids in the with field of any given character?
How would I query the database if I want to get all the characters that are n steps away from a given node?