Check if collection/schema already exists and if populated

SOLVED!

In my scripts I usually have a first section that defines a collection and then populates it, followed by a second section with the queries.

Of course if run this again it will throw an error when attempting to create the collection.

What is the correct Python V4 way of finding if collection exists and/or if it has objects inside it, so that I could skip the creation section and go directly to the queries?

Tried an horrible shortcut by deleting it with wclient.collections.delete(collname)
since my learning collections are small, but of course if this was a real project with many objects this would be a waste.
Thanks

2 Likes

Looking through the collection class in the code gave me the solution:

if not wclient.collections.exists(collname):
    define, create and add objects
2 Likes

That’s right.

One thing we (or at least I) do in recipes or python notebooks is to delete the class without even checking, so we make sure we have a brand new class to work with.

THanks for sharing :slight_smile:

1 Like