Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

my conncetion code looks like this:

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

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading