Reputation: 338
I've a simple document called 'agents' under a collection named 'mycoll' with data set something like below:
{
'metadata': {
'agent-ids': ['fdfd', 'asdfasdf', 'rerere'],
'agent_ids': ['foo1', 'booo']
}
I got the document snapshot:
snapshot = firestore.client().document('mycoll/agents').get()
If I try to access 'agent-ids' field name using get() method on this snapshot:
agent-list-with-hypens = snapshot.get('metadata.agent-ids')
ValueError: Path metadata.agent-ids not consumed, residue: -ids
However, If I try to access 'agent_ids' using get() method, that works just fine:
print(snapshot.get('metadata.agent_ids'))
['foo1', 'booo']
My question is what is causing this different behavior for field-names with an '-' and why? Any documentation which explains about this? I understand that snapshot.get() accpets a FieldPath argument instead of plain string but existing API documentation does not warn that field-names with an '-' are not allowed in field-path name strings delimited by '.'
In fact, snapshot.get(firestore.client().field_path('metadata', 'agent-ids'))
works just fine.
Upvotes: 1
Views: 1052
Reputation: 301
Based on the documentation, here are the constraints on field paths:
So a field name/path containing dash will raise ValueError. The above constraints also explain why snapshot.get(firestore.client().field_path('metadata', 'agent-ids'))
works just fine is because the field name is enclosed in backticks.
Upvotes: 1