gpt4 book ai didi

json - 如何将 JavaScript 函数存储到 mongoose 文档中?

转载 作者:太空宇宙 更新时间:2023-11-04 01:12:45 27 4
gpt4 key购买 nike

我需要将一些数据和关联的函数存储到mongodb文档中。

{name:"data1",event:function(){ /* some code */ }}
{name:"data2",event:function(){ /* some other code */ }}

我正在为我的项目使用mongoose.js ORM。我应该如何为此编写我的schema

引用 Mongoose guide

The permitted SchemaTypes are String, Number, Date, Buffer, Boolean, Mixed, ObjectId and Array.

但是如果你检查mongodb允许的datatypes,你可以找到存储js函数的方法,如mongo-db-data-types-article中提到的

Code class a special class that let’s you store javascript functions in Mongo DB, can also provide a scope to run the method in

我在 Mongoose 上找不到上述数据类型。有什么想法吗?

最佳答案

该模块为Mongoose添加功能支持:https://github.com/aheckmann/mongoose-function

关于json - 如何将 JavaScript 函数存储到 mongoose 文档中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14952870/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com