小编Vic*_*tor的帖子

如何解决 Mongo 中的“MongoError:E11000 重复键错误集合”错误?

我已经为新项目创建了一个新的 Mongo 集合,但是当我尝试创建新用户时,出现以下错误:

\n
MongoError: E11000 duplicate key error collection: GestorMedico.users index: username_1 dup key: { username: null }\n
Run Code Online (Sandbox Code Playgroud)\n

我的用户架构如下:

\n
const { 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);\n
Run Code Online (Sandbox Code Playgroud)\n

我的功能如下:

\n
userCtrl.createUser = async (req, res) => …
Run Code Online (Sandbox Code Playgroud)

javascript mongoose mongodb node.js

7
推荐指数
1
解决办法
2万
查看次数

如何使用 Swagger 在 @ApiResponse 中添加示例?

我想在我的方法中添加一个使用 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 spring swagger swagger-ui swagger-2.0

6
推荐指数
2
解决办法
2万
查看次数