
I'm using the nodejs server sdk and awaiting for the attribute to be created and then I'm trying to add a document to the collection. But the await gets completed even with processing status and then when my server tries to add a document, unknown attribute error pops up.

newRoomDatabaseId,
"participants",
"isMicOn",
true
);
console.log(x.status);
await db.createDocument(
newRoomDatabaseId,
"participants",
roomData.admin_username,
{
isAdmin: true,
isModerator: true,
isSpeaker: true,
isMicOn: false,
}
);```

x.status shows processing even after the async call gets completed

And i have added three more create attribute calls to create other attributes in the data given to create the doc

Yes, this is expected. The API call returns when the job is queued. You'll have to poll for when the status is available

I checked the status after 40 seconds and its still under processing.

Is there any other way to check if the attribute is available ?

So right now it's still processing?

Yeahh

I just added a delay of 40 seconds and then checked the x.status . It show’s processing, but now the document gets added correctly.

What do you mean you added a delay? And how are you checking the status?

I added a time delay as a promise for 40 seconds and then when it resolves, Im just console logging x.status

Can you share your code?

newRoomDatabaseId,
"participants",
"isMicOn",
true
);
console.log(x.status); //Prints processing
await new Promise(resolve => setTimeout(resolve, 5000));
console.log(x.status); //Prints processing
await db.createDocument(
newRoomDatabaseId,
"participants",
roomData.admin_username,
{
isMicOn: false,
}
);
console.log(x.status); //Prints processing```

That doesn't work...you're just waiting and then looking at the same status string from when it was first created

Can you please help me with what has to be done here to achieve my requirement?

You need to fetch the attribute/collection again after waiting to see the new status

Okayy. Thanks @Steven . Will check that in sometime.

Hey @Steven This is the algorithm I came up with.
// Polling until all the required attributes are added to the collection
while (true) {
let participantCollection = await db.getCollection(
newRoomDatabaseId,
"participants"
);
let attributesAvailable = true;
participantCollection.attributes.forEach((attribute) => {
if (attribute.status != "available") {
attributesAvailable = false;
}
});
if (attributesAvailable === true) {
break;
}
}

It now works fine but I'm not sure if this is efficient. Need help in this regard.

You should probably add some sort of delay between each iteration and set some sort of maximum so you don't get stuck in an infinite loop

Okayy. Will do that. Thanks @Steven
Recommended threads
- Error 1.7.4 console team no found
In console when i go to auth, select user, select a membership the url not work. Only work searching the team. It is by the region. project-default- and i get ...
- functions of 1.4 not work on 1.7
Hi, i updated of 1.4 to 1.7 but the function not work i get it error. Do I need to build and deploy the functions again?
- Login Error 500
Hey i have that Problem, i upgrade to the latest version and now i have this error but only on my custom domain not the main domain.. when i try to login
