1. <small id='PfcFJ'></small><noframes id='PfcFJ'>

    <tfoot id='PfcFJ'></tfoot>
      <bdo id='PfcFJ'></bdo><ul id='PfcFJ'></ul>

  2. <i id='PfcFJ'><tr id='PfcFJ'><dt id='PfcFJ'><q id='PfcFJ'><span id='PfcFJ'><b id='PfcFJ'><form id='PfcFJ'><ins id='PfcFJ'></ins><ul id='PfcFJ'></ul><sub id='PfcFJ'></sub></form><legend id='PfcFJ'></legend><bdo id='PfcFJ'><pre id='PfcFJ'><center id='PfcFJ'></center></pre></bdo></b><th id='PfcFJ'></th></span></q></dt></tr></i><div id='PfcFJ'><tfoot id='PfcFJ'></tfoot><dl id='PfcFJ'><fieldset id='PfcFJ'></fieldset></dl></div>

  3. <legend id='PfcFJ'><style id='PfcFJ'><dir id='PfcFJ'><q id='PfcFJ'></q></dir></style></legend>

    1. Mongoose:Coffeescript 中的递归嵌入文档

      时间:2024-04-19
      • <bdo id='ZvLWR'></bdo><ul id='ZvLWR'></ul>

        <tfoot id='ZvLWR'></tfoot>

            <small id='ZvLWR'></small><noframes id='ZvLWR'>

                <i id='ZvLWR'><tr id='ZvLWR'><dt id='ZvLWR'><q id='ZvLWR'><span id='ZvLWR'><b id='ZvLWR'><form id='ZvLWR'><ins id='ZvLWR'></ins><ul id='ZvLWR'></ul><sub id='ZvLWR'></sub></form><legend id='ZvLWR'></legend><bdo id='ZvLWR'><pre id='ZvLWR'><center id='ZvLWR'></center></pre></bdo></b><th id='ZvLWR'></th></span></q></dt></tr></i><div id='ZvLWR'><tfoot id='ZvLWR'></tfoot><dl id='ZvLWR'><fieldset id='ZvLWR'></fieldset></dl></div>

                  <tbody id='ZvLWR'></tbody>
              1. <legend id='ZvLWR'><style id='ZvLWR'><dir id='ZvLWR'><q id='ZvLWR'></q></dir></style></legend>

                本文介绍了Mongoose:Coffeescript 中的递归嵌入文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                基于 此示例(有效):

                var Comment = new Schema();
                
                Comment.add({
                    title : { type: String, index: true }
                  , date : Date
                  , body : String
                  , comments : [Comment]
                });
                

                我想创建一个 CoffeeScript 版本

                I wanted to create a CoffeeScript version

                mongoose = require 'mongoose'
                Schema = mongoose.Schema
                
                Person = new Schema
                Person.add
                  mother: Person
                  father: Person
                

                但是它返回一个错误,我不明白为什么

                However it returns an error and I don't understand why

                TypeError: undefined is not a function
                    at CALL_NON_FUNCTION_AS_CONSTRUCTOR (native)
                    at Function.interpretAsType (/path/node_modules/mongoose/lib/schema.js:202:10)
                    at Schema.path (/path/node_modules/mongoose/lib/schema.js:162:29)
                    at Schema.add (/path/node_modules/mongoose/lib/schema.js:110:12)
                    at Object.<anonymous> (/path/Models/test.coffee:6:10)
                    at Object.<anonymous> (/path/Models/test.coffee:10:4)
                    at Module._compile (module.js:411:26)
                    at Object.run (/usr/local/lib/node_modules/coffee-script/lib/coffee-script.js:57:25)
                    at /usr/local/lib/node_modules/coffee-script/lib/command.js:147:29
                    at /usr/local/lib/node_modules/coffee-script/lib/command.js:115:26
                

                好的,我发现当 Person 不是数组(在括号中)时它不起作用,但是为什么呢?

                Okay, I found out that it doesn't work when Person isn't an array (in brackets), but why?

                推荐答案

                嵌入文档只能作为数组中的项存在.这是设计使然,您可以向作者询问他们的原因:)

                Embedded documents can only exist as items in an array. That is by design, you can ask the authors for their reasons :)

                您可能想要使用 DBRef:

                Person = new Schema
                  mother: { type: Schema.ObjectId, ref: 'Person' }
                  father: { type: Schema.ObjectId, ref: 'Person' }
                

                (请注意,您不需要 add 调用)

                (notice you don't need the add call)

                请参阅 有关填充/DBRef 的文档.

                这篇关于Mongoose:Coffeescript 中的递归嵌入文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在 coffeescript 中启用和声语法支持? 下一篇:非法的继续声明?

                相关文章

                  <bdo id='BNCVF'></bdo><ul id='BNCVF'></ul>

                  <tfoot id='BNCVF'></tfoot>
                  1. <legend id='BNCVF'><style id='BNCVF'><dir id='BNCVF'><q id='BNCVF'></q></dir></style></legend>
                    <i id='BNCVF'><tr id='BNCVF'><dt id='BNCVF'><q id='BNCVF'><span id='BNCVF'><b id='BNCVF'><form id='BNCVF'><ins id='BNCVF'></ins><ul id='BNCVF'></ul><sub id='BNCVF'></sub></form><legend id='BNCVF'></legend><bdo id='BNCVF'><pre id='BNCVF'><center id='BNCVF'></center></pre></bdo></b><th id='BNCVF'></th></span></q></dt></tr></i><div id='BNCVF'><tfoot id='BNCVF'></tfoot><dl id='BNCVF'><fieldset id='BNCVF'></fieldset></dl></div>

                    <small id='BNCVF'></small><noframes id='BNCVF'>