如何在mongodb中定义对象引用数组

时间:2019-03-01 21:54:33

标签: mongodb tags

我是NoSQL的新手,是否可以在mongodb验证程序中定义引用数组,以便集合可以存储标签集合的ID? 我对集合有以下定义:

db.createCollection("foos", {
  validator:{
    bsonType: "object",
    required: [ "a", "tags"],
    properties: {
      timestamp:{
        bsonType: "timestamp"
      },
      a:{
        bsonType: "string"
      },
      tags:{
        bsontype: ["HERE I NEED TO HAVE REFERENCES TO COLLECTION OF TAGS"]
      }
    }
  }
});

标签集合如下:

{
  {
    _id: "123ABC",
    tag: "apple"
  },
  {
    _id: "232XYZ"
    tag: "orange"
  }
}

实现taggin关系是否正确?

0 个答案:

没有答案