I want to use code to get a collection’s fields, even if it is empty (contains no items). When it’s not empty, Query().find() does the trick easily (every item will be an object with the fields as keys), but when it’s empty, query().find() doesn’t return any items… so…
Any suggestions?
BTW, preferably this will not rely on datasets, as it needs to run in the backend.
Hi Tal,
This might work:
-
save a dummy record with just one field
-
read it back to get the structure
-
delete it in order to clean up
But, why not just keep the structure inside of your code? After all, you know what fields are in the collection, so just create the structure inside the code one time and it’ll then always be available.
I hope this helps,
Yisrael
Hi Yisrael.
Yeah, I guess that might work.
I wanted to avoid saving it in the code itself, simply because it is needed for more than one collection, and it will start to get messy, but no biggie.
I might even just not do it at all, maybe it’s pointless… we’ll see.
Thanks anyway
T
Glad to help