1、还原数据库
mongorestore --username root --password root --authenticationDatabase admin --db geek mock
2、语法
//创建校验 db.createCollection("students3", { validator: { $jsonSchema: { bsonType: "object", required: ["name", "year", "major", "address"], properties: { name: { bsonType: "string", description: "must be a string and is required" }, year: { bsonType: "int", minimum: 2017, maximum: 3017, description: "must be an integer in [ 2017, 3017 ] and is required" }, major: { enum: ["Math", "English", "Computer Science", "History", null], description: "can only be one of the enum values and is required" }, gpa: { bsonType: ["double"], description: "must be a double if the field exists" }, address: { bsonType: "object", required: ["city"], properties: { street: { bsonType: "string", description: "must be a string if the field exists" }, city: { bsonType: "string", "description": "must be a string and is required" } } } } } } }) //创建 db.students3.insertOne({ "name": "wang", "year": NumberInt("2019"), "major": "English", "address": { "city": "hz" } })
3、BSON