Skip to content

DB Randomly Does not Find Any Document #171

Open
@johachi

Description

@johachi

Description

The DB sometimes randomly returns "no documents" when using $elemMatch in the match.

Setup

Share link: https://mongoplayground.net/p/AylVo0AlDWF

Database type

bson

Database content

[
  {
    "_id": ObjectId("000000000000000000000111"),
    "triggers": [
      {
        "trigger": "sa",
        "method": "liveness_check",
        "source": {
          "service": "example",
          "type": "project",
          "identifier": "222222222222222222222222"
        }
      }
    ]
  },
  {
    "_id": ObjectId("000000000000000000000222"),
    "triggers": [
      {
        "trigger": "sa",
        "method": "liveness_check",
        "source": {
          "service": "example",
          "type": "project",
          "identifier": "111111111111111111111111"
        }
      }
    ]
  },
  {
    "_id": ObjectId("000000000000000000000333"),
    "triggers": []
  },
  {
    "_id": ObjectId("000000000000000000000444"),
    "triggers": [
      {
        "trigger": "sa",
        "method": "liveness_check",
        "source": {
          "service": "example",
          "type": "project",
          "identifier": "ff"
        }
      },
      {
        "trigger": "ff",
        "method": "liveness_check",
        "source": {
          "service": "example",
          "type": "project",
          "identifier": "222222222222222222222222"
        }
      }
    ]
  }
]

Query

db.collection.find({
  triggers: {
    $elemMatch: {
      "trigger": "sa",
      "method": "liveness_check",
      "source": {
        "service": "example",
        "type": "project",
        "identifier": "222222222222222222222222"
      }
    }
  }
})

Expected Result

[
  {
    "_id": ObjectId("000000000000000000000111"),
    "triggers": [
      {
        "method": "liveness_check",
        "source": {
          "identifier": "222222222222222222222222",
          "service": "example",
          "type": "project"
        },
        "trigger": "sa"
      }
    ]
  }
]

Actual Result

Sometimes same as the expected result, sometimes no document found

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions