I'm just getting started with GameSparks and I haven't been able to find much info about this.
It doesn't seem that a runtime collection can be locked explicitly, but this topic says that locks happen automatically; would it be possible to get clarification on what that means? Would the first read request on a runtime collection in a cloud code script automatically secure a lock on that collection for the entire runtime of that script?
I'm looking at a use case where I need to randomly generate a unique user-friendly string, which involves checking the record for existence before inserting. I need to be sure that the state of the collection hasn't changed between the moment I check and the moment I insert. Will that 'work' automatically?
Best Answer
B
Baris Tumerkan
said
over 4 years ago
It won't work automatically. What they're talking about there is for a single operation on the runtime collection.
Checking for the existence of the string, and then inserting it are 2 operations. Anything can happen in between them.
What you could do is, create a unique index on your field (https://docs.mongodb.com/manual/core/index-unique/), and then if someone has already inserted that string, your insert operation will fail as you want.
It won't work automatically. What they're talking about there is for a single operation on the runtime collection.
Checking for the existence of the string, and then inserting it are 2 operations. Anything can happen in between them.
What you could do is, create a unique index on your field (https://docs.mongodb.com/manual/core/index-unique/), and then if someone has already inserted that string, your insert operation will fail as you want.
1 person likes this
B
Benjamin Grob
said
over 4 years ago
Thanks, that's perfect - that field needs to be unique indexed so it fits what I need to do!
Benjamin Grob
Hi there,
I'm just getting started with GameSparks and I haven't been able to find much info about this.
It doesn't seem that a runtime collection can be locked explicitly, but this topic says that locks happen automatically; would it be possible to get clarification on what that means? Would the first read request on a runtime collection in a cloud code script automatically secure a lock on that collection for the entire runtime of that script?
I'm looking at a use case where I need to randomly generate a unique user-friendly string, which involves checking the record for existence before inserting. I need to be sure that the state of the collection hasn't changed between the moment I check and the moment I insert. Will that 'work' automatically?
It won't work automatically. What they're talking about there is for a single operation on the runtime collection.
Checking for the existence of the string, and then inserting it are 2 operations. Anything can happen in between them.
What you could do is, create a unique index on your field (https://docs.mongodb.com/manual/core/index-unique/), and then if someone has already inserted that string, your insert operation will fail as you want.
1 person has this question
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstBaris Tumerkan
It won't work automatically. What they're talking about there is for a single operation on the runtime collection.
Checking for the existence of the string, and then inserting it are 2 operations. Anything can happen in between them.
What you could do is, create a unique index on your field (https://docs.mongodb.com/manual/core/index-unique/), and then if someone has already inserted that string, your insert operation will fail as you want.
1 person likes this
Benjamin Grob
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2486 topics