How to use mongoose model schema with dynamic keys?

后端 未结 4 1202
轮回少年
轮回少年 2021-01-13 17:51

i\'m using mongoose with nodejs, and i need to create a dynamic schema model, this is my code:

schema.add({key : String});

key = \"user_nam

4条回答
  •  清歌不尽
    2021-01-13 18:03

    You can do like this:

    posts: { type: Object }
    

    And inside posts key, you can implement any key-value pair you would like to

提交回复
热议问题