Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple normalized responses for same survey with same userId #465

Open
SachaG opened this issue Nov 28, 2024 · 0 comments
Open

Multiple normalized responses for same survey with same userId #465

SachaG opened this issue Nov 28, 2024 · 0 comments

Comments

@SachaG
Copy link
Member

SachaG commented Nov 28, 2024

I noticed that for some older surveys we seem to have multiple copies of the same survey for the same user, which should in theory not be possible.

It's probably some bug due to importing those responses from a previous system, but I thought I'd make a note of it.

Screenshot 2024-11-28 at 11 26 21

Aggregation used:

[
  {
    // Filter documents where both userId and editionId exist
    $match: {
      userId: {
        $exists: true,
        $ne: null
      },
      editionId: {
        $exists: true,
        $ne: null
      }
    }
  },
  {
    // Group by userId and editionId
    $group: {
      _id: {
        userId: "$userId",
        editionId: "$editionId"
      },
      count: {
        $sum: 1
      } // Count the documents in each group
    }
  },
  {
    // Optional: Sort by count in descending order
    $sort: {
      count: -1
    }
  },
  {
    // Optional: Project the fields for better readability
    $project: {
      _id: 0,
      // Hide the _id field
      userId: "$_id.userId",
      editionId: "$_id.editionId",
      count: 1
    }
  }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant