是否可以使用连接更新一个集合

时间:2013-02-24 11:19:07

标签: node.js mongodb mongoose

我有两个带有以下架构的集合

var document = new TestDocAccess({
  documentId: '50dc37d6022b2bdd07000004',
  userId : "1234",
  userName : "Test Name",
  identifier : [String]
});

var master = new TestDocMaster({
  documentId: document._id,
  masterId: "50a5e7bcda3c4d557f00847a"
});

是否仍然使用documents集合中的masterId来更新master集合中的字段。

1 个答案:

答案 0 :(得分:2)

必须在您的应用程序中创建基于文档的数据库(如MongoDB)中的任何“连接”。所以基本上你必须首先从master collection查询id,然后使用该id来更新documents collection中的正确文档。