gpt4 book ai didi

javascript - 如何在 MongoDB 模式声明中使用 "Long"类型?

转载 作者:太空宇宙 更新时间:2023-11-03 22:52:26 29 4
gpt4 key购买 nike

我想这是一个愚蠢的问题,但我想做这样的事情

var mongoose = require('mongoose');
var Long = require("long");

var UserSchema = new mongoose.Schema({
id: Long(),
name: String,
completed: Long(),
note: String,
updated_at: { type: Date, default: Date.now },
});

但它不起作用,“无法设置‘低’属性”。我知道这一点,因为我没有在“Long”构造函数中传递参数,但即使我不输入“()”,它也不起作用。我有点迷失了^^'

抱歉我的英语不好^^'

最佳答案

您应该使用专门为 Mongoose 设计的模块,例如 mongoose-long :

var mongoose = require('mongoose')
require('mongoose-long')(mongoose);
var Long = mongoose.Schema.Types.Long;

var UserSchema = new mongoose.Schema({
id : Long,
name : String,
completed : Long,
note : String,
updated_at : { type: Date, default: Date.now },
});

关于javascript - 如何在 MongoDB 模式声明中使用 "Long"类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37904973/

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