How does this query work on Mongo Dedicated and not on Mongo Serverless?

I have been playing around and found a query which works on Mongo Dedicated, but not on Mongo Serverless. It’s simple and it’s not part of Serverless limitations as far as i have checked.

Ok, so i have the following collection:

[
{
“domain”: “http://example.com”,
“name”: “example”,
“result”: [
{
“isRunning”: true
}
],
“resultIsRunning”: [
true
]
}
]

When I run following query on Serverless:

[
{
$match: {
_id: ObjectId(“663cc77517d2b8f137746b3b”),
},
},
{
$addFields: {
resultIsRunningMapped: {
$map: {
input: “$result”,
as: “res”,
in: “$$res.isRunning”,
},
},
},
},
{
$match: {
resultIsRunning: {
$elemMatch: {
$eq: true,
},
},
},
},
{
$match: {
resultIsRunningMapped: {
$elemMatch: {
$eq: true,
},
},
},
},
]

  1. Stage outputs the object as expected, but the 4th stage does not.

I found that modifying the 2. stage like:

resultIsRunningMapped: {
$map: {
input: { $ifNull: [“$result”, ] },
as: “res”,
in: “$$res.isRunning”,
},
}

or like:

resultIsRunningMapped: {
$map: {
input: “$result”,
as: “res”,
in: { $toBool: “$$res.isRunning” },
},
}

will fix the problem, but i have zero clue why it fixes the problem.

NOTE: this only happens on Mongo Serverless, on Mongo Dedicated it work just fine without any fixes - which is very unexpected.

Has anyone encountered a similar problem or knows whats the problem here ?

Thanks in advance,
Lazar

Hi, can you please provide a URL to you Serverless instance?

To ensure privacy, I have sent you instance details on your email.