【问题标题】:What will be typescript type of mongoose bin datamongoose bin 数据的打字稿类型是什么
【发布时间】:2023-02-25 13:06:04
【问题描述】:

我正在为猫鼬中的按位运算符编写类型。

在那,它说

The field value must be either numeric or a BinData instance. Otherwise, 
$bitsAllClear
 will not match the current document.

这里 BinData 的打字稿类型应该是什么?

参考:https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#mongodb-query-op.-bitsAllClear

【问题讨论】:

    标签: typescript


    【解决方案1】:

    你可以这样写

    type BinData = {
      subtype: number;
      buffer: Buffer;
    };
    

    并像这样在您的模式中使用它

    const schema = new mongoose.Schema({
      bitmaskBinData: {
        type: Number | BinData, // allow numeric or BinData values
        required: true
      }
    });
    

    【讨论】:

    • 谢谢,您使用 chatGpt 答案了吗?你也可以解释你的代码吗?
    猜你喜欢
    • 2018-06-13
    • 2016-11-06
    • 2019-01-10
    • 1970-01-01
    • 2022-01-19
    • 2019-01-26
    • 1970-01-01
    • 1970-01-01
    • 2016-07-29
    相关资源
    最近更新 更多