首页 > 解决方案 > 为什么 Postman 和 mongoDb db.getCollectionNames 返回空数组?

问题描述

我有一个连接到本地 mongoDB 数据库的 Spring Boot 应用程序。当我尝试从集合中获取所有记录时,它返回一个空数组。

Facture.class

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection = "Facture")
public class Facture {

    @Id
    private Long id_facture;
    private int num_facture;
    private double prix;
    private String methode_paiement;

资料库

import com.app.Model.Facture;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface FactureDao extends MongoRepository<Facture, Long> {
}

邮递员结果

{
    "timestamp": "2020-03-25T00:56:13.597+0000",
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/api/v1/all"
}

标签: mongodbspring-bootrestapipostman

解决方案


答案是应该将 id 类型更改为 String 就可以了


推荐阅读