Firestore Query - Maximum call stack size exceeded

I’m trying to run a Firestore query to remove duplicates.

The problem is: there are too many documents in the result, so I get a “ERROR: Maximum call stack size exceeded”.

What I’m trying to do:

  1. Query Firestore with a simple where.

{"structuredQuery": {"where": {"fieldFilter": {"field": {"fieldPath": "source"},"op": "EQUAL", "value": {"stringValue": "ServiceName}}}, "from": [{"collectionId":"deals"}]}}

  1. Run a Function to select duplicates
const seen = new Set();

return items.filter(i => {
  if (seen.has(i.json.id)) return true;
  seen.add(i.json.id);
  return false;
});
  1. Run a Firestore node deleting the duplicated items.

Any idea how can I get this done for large queries?

Unfortunately in the beginning of my project I didn’t check for duplicates before submiting to Firebase and I ended up with a database full of dups.

Thanks.

Amazing, found the answer myself.

I just added a SELECT to my structuredQuery to show the only fields I needed, now I’m able to reproduce all the results.

I’ll leave this here for prosperity:

{
	"structuredQuery": {
		"select": {
			"fields": [{
				"fieldPath": "id"
			}, {
				"fieldPath": "dealURL"
			}]
		},
		"where": {
			"fieldFilter": {
				"field": {
					"fieldPath": "source"
				},
				"op": "EQUAL",
				"value": {
					"stringValue": "ServiceName"
				}
			}
		},
		"from": [{
			"collectionId": "deals"
		}]
	}
}

Cheers

1 Like

Hi @EB_BR, thanks so much for bringing this up and even more for sharing your solution! I’ll also add this point to our internal list for possible future improvements for a closer look.