//创建集合
db.createCollection(“role”, {
validator: {
$jsonSchema: {
bsonType: “object”,
required: [ “roleId”, “roleName”],
properties: {
roleId: {
bsonType: “string”,
description: “角色ID”
},
roleName: {
bsonType: “string”,
description: “角色名”
},
roleHeadIcon: {
bsonType: “string”,
description: “角色头像ID”
},
lv: {
bsonType: “int”,
description: “等级”
},
exp: {
bsonType: “int”,
description: “经验”
}
}
}
}
})
//插入集合
db.role.insertOne({
“roleId”: “inu1_1001”, “roleName”: “quanyecha1”
});
//查询
db.role.find().forEach(printjson);