共享_ids Mongoose

时间:2017-05-19 17:59:37

标签: mongoose

所以,我有两个需要标识符的集合。使用Mongo的建议,我创建了第三个标识符集合:

const Identifier = Schema(
{
    _id : { type: Buffer, required: true }
});

const FirstCollection = Schema(
{
    identifier: { type: Buffer, ref: "Identifier", required: true }
})

const SecondCollection = Schema(
{
    identifier: { type: Buffer, ref: "Identifier", required: true }
})

然后,当我们创建它时:

var x = new Identifier();
x.save();
new FirstCollection({ identifier: x });

到目前为止,我很好,我想知道我是否可以在集合中使用此标识符作为_id本身:

FirstCollection = Schema(
{
   _id: { type: Buffer,
        ref: "Identifier",
        required: true }
})

这有意义吗?

0 个答案:

没有答案