Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create an empty collection #4

Open
Raspberry42 opened this issue Feb 5, 2021 · 2 comments
Open

Create an empty collection #4

Raspberry42 opened this issue Feb 5, 2021 · 2 comments

Comments

@Raspberry42
Copy link
Owner

Hello jerome!

Is it possible to add an empty collection? (without document)

I tried this:

public static function addEmptyCollection (string $collection) {
    $db = self::connectFirestore();
    $db->collection($collection)->document('empty')->set([]);
    $db->collection($collection)->document('empty')->delete();
}

But it also removes the collection ...

You have an idea ?
Thank you.

@jeromegamez
Copy link

jeromegamez commented Feb 6, 2021

That's not possible by design: if a collection is empty, it is as if it doesn't exist. It's actually a little bit similar to PHP:

$var = null; // exists, but nothing is in it

But, of course, it's not that simple 😅

https://stackoverflow.com/a/57858387/284325

https://groups.google.com/g/google-cloud-firestore-discuss/c/o3tUFJpPYKc?pli=1

@Raspberry42
Copy link
Owner Author

Ok I understood.
Thanks Jerome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants