(AtlasError) [key] is not allowed in this atlas tier

Greetings,

I’m using Go with the official MongoDB driver to run an aggregation query with three stages (match, addFields, project), but I’m getting the following error:

(AtlasError) coordinates.coordinates is not allowed in this atlas tier

The exact same query works fine in MongoDB Compass and the same query without the match stage works in Go, so the issue appears to be with the match stage:

matchStage := bson.M{
	"coordinates.coordinates": bson.M{
		"$geoWithin": bson.M{
			"$geometry": bson.M{
				"type":        "Polygon",
				"coordinates": coordinates,
			},
		},
	},
}

The same query works in Go as a find query, so I’m guessing that the free tier M0 that I’m currently using limits geospatial matching in aggregation, but I’m not quite sure since this limitation is not listed among the known limitations.

The size of the whole collection is only 4 MB and I’m using the latest version of the driver as well as Go.

Could you please advise on:

  1. What is the precise issue?
  2. Is there a way to correct or circumvent it?
  3. If this is a deliberate limitation, which is the cheapest tier one needs to run this query?

Thank you!

Hi @SMthefirst, welcome to the forums!

  1. What is the precise issue?

Given the information provided, it seems that this error is because the aggregation stage specified coordinates.coordinates at the top level instead of $match.

For example you should be able to use the following code:

    geoWithinStage := bson.D{{"coordinates.coordinates", bson.D{
		{"$geoWithin", bson.D{
			{"$geometry", bson.D{
				{"type", "Polygon"},
				{"coordinates", coordinates}},
			}},
		}},
	}}
	pipeline := mongo.Pipeline{
		{{"$match", geoWithinStage}},
	}
	cursor, err := collection.Aggregate(context.Background(), pipeline)

You can also print pipeline variable in the above example to see the Aggregation Pipeline before being sent to the server.

The same query works in Go as a find query, so I’m guessing that the free tier M0 that I’m currently using limits geospatial matching in aggregation

This is likely because you can use $geoWithin in find() without specifying the $match stage. The first entry is the name of the field instead of an operator i.e. coordinates.coordinates

(AtlasError) coordinates.coordinates is not allowed in this atlas tier

In this case, the error message is misleading. I’ll raise this issue internally for an improvement.
As you should be able to use $match with $geoWithin operator in M0 Free Tier (lowest tier)

If the issue persists, please provide:

  • Example documents in the collection
  • More snippet of the Go code
  • MongoDB Go driver version

Regards,
Wan.

3 Likes

Thank you for your help, sir!

This was a very silly oversight on my part and then instead of solving the issue with the query, I got confused by the misleading error message and looked for solutions elsewhere (thank you for addressing that internally).

A simple addition of "$match": bson.M{ … }, at the top level of my matchStage query solved the issue (I prefer the bson.M{} syntax because it’s cleaner, but please let me know if this could present further issues in this context).

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.

Hi @SMthefirst,

Glad you got it working!

The difference here is that bson.D is an ordered representation of a BSON document. This should be used when the order of the elements matters, such as MongoDB command documents. If the order of the elements does not matter, you can use bson.M instead.

In the context of a single $match pipeline stage as the example shown here, you could use bson.M.

Regards,
Wan.

2 Likes