Recursive elements in Schema : Mongoose modelling

后端 未结 1 443
终归单人心
终归单人心 2020-12-06 18:12

Any idea how to model a Tree document in Mongoose Schema?

var TreeSchema = new Schema({
    \"Non-leafNode\": {
        \"children\": [
            {
                


        
相关标签:
1条回答
  • 2020-12-06 18:49

    From https://groups.google.com/forum/#!topic/mongoose-orm/0yUVXNyprx8:

    By design, it might work. There's no tests for this. I have Schema#add in there for this purpose, to produce recursive references:

    var Tasks = new Schema();
    Tasks.add({
       title     : String
     , subtasks  : [Tasks]
    });
    

    So you need to construct the recursion step by step.

    0 讨论(0)
提交回复
热议问题