Skip to content

MongoDB v6.0.2 or mongoplayground bug? #153

@rickhg12hs

Description

@rickhg12hs

While exploring ways to retrieve or "$merge"/"$out" unique documents from a collection, I ran across the following "oddity".

mongoplayground.net example

mongoplayground mgodatagen configuration:

[
  {
    "collection": "collection",
    "count": 100,
    "content": {
      "key1": {
        "type": "int",
        "minInt": 0,
        "maxInt": 1
      },
      "key2": {
        "type": "int",
        "minInt": 0,
        "maxInt": 1
      }
    }
  }
]

Query:

db.collection.aggregate([
  {
    "$unset": "_id"
  },
  {
    "$group": {
      "_id": "$$ROOT"
    }
  },
  {
    "$replaceWith": "$_id"
  }
])

Result: (should just be 4 docs, but it's not - there are repeats)

[
  {
    "key1": 1,
    "key2": 1
  },
  {
    "key1": 1,
    "key2": 0
  },
  {
    "key1": 1,
    "key2": 0
  },
  {
    "key1": 1,
    "key2": 1
  },
  {
    "key1": 0,
    "key2": 0
  },
  {
    "key1": 0,
    "key2": 1
  },
  {
    "key1": 0,
    "key2": 0
  },
  {
    "key1": 0,
    "key2": 1
  }
]

Using the same collection and query on MongoDB Atlas, the expected output of just 4 documents was produced.

The MongoDB Atlas Cluster I used is at version 5.0.13 so maybe it's a MongoDB server regression?

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