我有一个以视频游戏为主题的Six Degrees of Separation应用程序,我想知道使用node.js和MongoDB实现广度优先搜索的最佳方法。
我的应用使用https://github.com/mongodb/node-mongodb-native进行MongoDB。
对于我正在使用的集合,我的文档如下所示:
{
_id: "Mega Man",
with: [
{ _id: "Wolverine", in: "Marvel vs. Capcom"},
{ _id: "Snake Man", in: "Mega Man's Soccer"}
]
}
如果我想要与Mega Man相关的角色,我需要一个查询来生成
[
{ _id: "Wolverine", with: [...]},
{ _id: "Snake Man", with: [...]}
]
所以:
我将使用哪些查询/查询来获取字符列表,每个字符的_id
对应于任何给定字符的_id
字段中的with
s ?
如果我想获取距离给定节点n
步距的所有字符,我将如何查询数据库?