我已经为新项目创建了一个新的 Mongo 集合,但是当我尝试创建新用户时,出现以下错误:
\nMongoError: E11000 duplicate key error collection: GestorMedico.users index: username_1 dup key: { username: null }\nRun Code Online (Sandbox Code Playgroud)\n我的用户架构如下:
\nconst { Schema, model } = require("mongoose");\n\nconst userSchema = new Schema({\n nombreEmpresa: {\n type: String,\n unique: true,\n required: true\n },\n email: {\n type: String,\n required: true\n },\n telefono: {\n type: String,\n required: true\n },\n contrase\xc3\xb1a: {\n type: String,\n required: true\n }\n}, {\n timestamps: true,\n versionKey: false\n});\n\nmodule.exports = model("Users", userSchema);\nRun Code Online (Sandbox Code Playgroud)\n我的功能如下:
\nuserCtrl.createUser = async (req, res) => …Run Code Online (Sandbox Code Playgroud) 我想在我的方法中添加一个使用 Swagger 的示例,我尝试了一些方法,但没有成功。
我有我的接口,我在其中定义方法:
@Api(value = "test API")
@RequestMapping("/api/v1/product")
public interface TestController {
@ApiOperation(
value = "Service that return a Product",
notes = "This service returns a Product by the ID",
nickname = "getProductById",
response = ProductResponse.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "The request has succeeded.", response = ProductResponse.class),
@ApiResponse(code = 500, message = "Internal server error.", response = ProductResponse.class) })
@GetMapping(
value = "/productById",
produces = { "application/json" }
)
ResponseEntity<ProductResponse> getProductById(@RequestParam(value = "productId", required = …Run Code Online (Sandbox Code Playgroud) java ×1
javascript ×1
mongodb ×1
mongoose ×1
node.js ×1
spring ×1
swagger ×1
swagger-2.0 ×1
swagger-ui ×1