mongodb 为什么我不能在$match管道聚合mongoose中使用布尔值?

ozxc1zmp  于 2023-11-17  发布在  Go
关注(0)|答案(1)|浏览(162)
const GambitSchema: Schema = new Schema({
    _id: { type: String, required: true, default: v4 },
    shortCode: {
        type: String,
        required: true,
        default: () => uid(),
        unique: true,
    },
    question: { type: String },
    options: { type: [String], require: true, length: 2 },
    correctOption: { type: Number, default: null },
    winningMultiple: { type: Number, required: true, default: 1.25 }
})

const GambitUserBetSchema: Schema = new Schema({
    _id: { type: String, required: true, default: v4 },
    discordID: { type: String, required: true },
    gambitId: { type: String, required: true },
    winningAmountClaimed: { type: Boolean, default: false },
})
export const GambitUserBet = model('GambitUserBet', GambitUserBetSchema)

export default model('Gambit', GambitSchema)

字符串
我使用下面的查询来获取用户并将其数据与其他集合中的文档合并结合起来

const gambitUser = await GambitUserBet.aggregate([
{
    $match: {
        discordID: "1234",
        winningAmountClaimed: true,
    },
},
{
    $lookup: {
        from: 'gambits',
        localField: 'gambitId',
        foreignField: '_id',
        as: 'gambit',
    },
},
])


但我得到以下错误:

error TS2769: No overload matches this call.
Overload 1 of 2, '(pipeline?: PipelineStage[], options?: AggregateOptions, callback?: Callback<any[]>): Aggregate<any[]>', gave the following error.
    Type 'boolean' is not assignable to type 'Expression'.
  Overload 2 of 2, '(pipeline: PipelineStage[], callback?: Callback<any[]>): Aggregate<any[]>', gave the following error.
    Type 'boolean' is not assignable to type 'Expression'.


我使用的是mongoose版本:6.2.3,我还没有安装@types/mongoose
我的连接代码看起来像这样:

import { connect as MongoConnect } from 'mongoose'
MongoConnect(
    process.env.MONGODB_URL || 'mongodb://mongodb.localhost:27017/f1fantasy',
)

dbf7pr2w

dbf7pr2w1#

在GitHub中提交了一些问题,您的问题与issue-11980有关,
在mongoose最新版本6.4.0以上是fixed

相关问题