Home > OS >  Why I cannot use boolean values in $match pipeline aggregate mongose?
Why I cannot use boolean values in $match pipeline aggregate mongose?

Time:07-09

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)

I'm using the following query to fetch user and combine it's data with document in other collection

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

But I'm getting the following error:

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'.

I'm using mongoose version: 6.2.3 and I've not installed @types/mongoose

my conncetion code looks like this:

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

CodePudding user response:

There are issues submitted in GitHub and your problem is related to issue-11980,

It is fixed in mongoose latest version above 6.4.0.

  • Related