I’m currently facing an issue when I’m trying to build a primary index right after the collection creation.
At startup, my app checks if required collection exists, and, if not, creates them.
To do so, I’m using the following code :
CollectionSpec collectionSpec = CollectionSpec.create(collectionName, databaseScope); this.getBucket().collections().createCollection(collectionSpec);
Then right at the following line, I’m creating the primary index for my collection, with the following code
QueryResult result = this.getScope(organization).query( String.format("CREATE PRIMARY INDEX `%s` ON `%s`", indexName, collectionName) );
And there comes my issue, if I’m putting a sleep (regular
TimeUnit.SECONDS.sleep(4);) of a couple of seconds between those lines, everything works fine. But if I’m not putting any sleep between those lines I’m getting an error message
Keyspace not found in CB datastore. Which seems to indicate that my collection does not exist.
So I’d like to know if there is some proper way to ensure that the collection is fully created synchronously so that my next line of code can use it already.
Thanks for your time