본문 바로가기

Node

[#. Node] DB에서는 Array 데이터가 보이지만 AdminBro 관리자 대시보드에서 Array 데이터가 보이지 않을 때 adminbro does not show array

반응형

 

 

 

 

 

 

 

쇼핑몰 웹어플리케이션을 기준으로

고객이 장바구니에 상품을 담으면 user 컬렉션에 있는 cart array에 데이터를 넣고 있다

근데 DB에는 데이터가 제대로 들어가고 확인도 가능하지만

아래 이미지에서처럼 adminbro 관리자 대시보드에서는 cart array에 데이터가 보이지 않는다

 

 

 

 

 

 

 

 

 

 

① Model.js

User 컬렉션에 cart 정보를 밀어넣고 있었기 때문에 User.js 파일을 수정한다

Cart라는 schema를 생성하고 User schema에서 Cart의 타입을 [Cart]로 수정한다 

 

const mongoose = require('mongoose');

const Cart = new mongoose.Schema({		// 추가
  id: {
    type: String
  },
  quantity: {
    type: Number
  },
  data: {
    type: Number
  }
})

const userSchema = mongoose.Schema({

    ...
    cart: {
      type: [Cart],			// 기존 type: Array => type: [Cart]로 수정
      default: []
    },
    ...
    
})

 

 

 

 

 

 

node 서버 재시작 후

장바구니에 제품을 2개 담고 확인하면

 

 

 

이렇게 아까는 비어 있던 Cart Array에 데이터가 잘 들어온다

 

 

 

 

 

 

 

 

 

 

 

 

 

같은 질문을 한 글이 있어서 아래에서 해결 방법을 참고했다

 

github.com/SoftwareBrothers/admin-bro/issues/135

 

Arrays with nested schemas don't show the content · Issue #135 · SoftwareBrothers/admin-bro

I think this is the only feature that is not implemented by admin-bro team. Adding this would make it a fully fledged admin panel tool. Does the Admin-bro team have a plan for adding that feature t...

github.com

 

 

 

 

 

 

 

반응형