MongoError: Too many fields

2

Hi,
We are migrating from MongoDB to DocumentDB and a problem has arisen: "MongoError: Too many fields". Aggregate works fine in MongoDB, but in DocumentDB it raised this error. So, what is the field limit to select/consider in an aggregate in DocumentDB?

asked 3 years ago668 views
2 Answers
1
Accepted Answer

I was unable to get the $project or $addFields stages to work with more than 50 fields and could not find any documentation surrounding this limit.

However, at least in the case of $project, it appears you can work around the limitation by combining multiple $addFields stages followed by a $replaceRoot stage:

db.mytable.aggregate([
  {
    $addFields: {
      out: {
        /** fields 1-50 */
      },
    },
  },
  {
    $addFields: {
      out: {
        /** fields 51-100 */
      },
    },
  },
  {
    $addFields: {
      out: {
        /** fields 101-150 */
      },
    },
  },
  {
    $replaceRoot: {
      newRoot: "$out",
    },
  },
]);
answered a year ago
-1

Hi. You'll need to identify which actual stage in the aggregation pipeline is triggering the error. I've seen this error before on the $group stage, when there are too many fields to group by, there's a limit of 50 group fields.

AWS
Mihai A
answered 2 years ago
  • Our team has hit the same issue when using an aggregate call with a state that contains about 90 items. That 50 limit that you suggest. Is it mentioned anywhere on the DocumentDB documentation page? For example on the "Amazon DocumentDB Quotas and Limits" section - I am not able to find any information about that limit there.

  • We are experiencing this exact same error trying to do an aggregate() with a single $project stage. In testing an arbitrary list of with null valued $project fields, any field count over 50 produces a Too many fields. error from the server. I currently have a need to transform our documents with over 250 fields and because of this limitation, am not sure how to do it. I'm hoping this is configurable or I can find a workaround.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions