iT邦幫忙

0

mongoose Schema 儲存 Dictionary 格式

如題,
想請問如何儲存進類似

dic = [{"key1": "key1_value"},
{"key2": "key2_value"},
{"key3": "key3_value"},
.
.
.
]

的格式

目前參考 mongoose官方文件
但是不太確定它可不可以儲存我想要的格式

以下是我撰寫的code,但不知道其正確性

const mongoose = require('mongoose');

const dicSchema = new Schema({
    dic:{
        type: [{}],
        default: undefined,
        required : false
    }   
});
module.exports = mongoose.model('dic',dicSchema);

懇請各位大大解答,感謝

dragonH iT邦超人 5 級 ‧ 2020-03-02 21:38:23 檢舉
>但是不太確定它可不可以儲存我想要的格式

p39212053 iT邦新手 4 級 ‧ 2020-03-03 16:29:31 檢舉
目前(菜)解法是

Schema.js

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const schema = new Schema({
欄位1 :{
type : [String],
required : true
}
});

並 post 資料格式為
["key1:value1", "key2:value2"]
將可以儲存為2個element

想請問有沒有更好的儲存方式QQ
可以實現 dictionary post 方法並儲存至資料庫
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答