Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Solved
  • Unsolved
  • Users
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Darkly)
  • No Skin
Collapse
brainCloud Forums
  1. Home
  2. Cloud Code
  3. Unique field for a Custom Entity

Unique field for a Custom Entity

Scheduled Pinned Locked Moved Cloud Code
cloud code scriptcuscloud code
3 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Reza Mortazavi
    wrote on last edited by
    #1

    I need to create an entity which must have an unique name in it's data.
    exp:

    {
     name: "blabla",
     ...
    }
    

    I can handle it by reading the whole table and check if there is no object with that name and then create the entity, but what can I do with concurrency?
    if someone else calls the create api in the same time and the same name it's not in db yet, then I can't notice it's a duplicate name, then we encounter a duplication.
    any workaround for this situations?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JasonL
      bitHeads
      wrote on last edited by
      #2
      This post is deleted!
      1 Reply Last reply
      0
      • J Offline
        J Offline
        JasonL
        bitHeads
        wrote on last edited by
        #3

        Hi Reza, a simple workaround I would recommend is using our atomic methods, such as IncrementGlobalStats, to form the field values with the returned value of that method and some other characters you selected. (defined a global statistic ahead of time, call IncrementGlobalStats() get the returned current value of the global statistic, e.g. 123, then combine with the name you selected to a unique name, such as name_123)

        1 Reply Last reply
        0
        • K kuabs referenced this topic on

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Solved
        • Unsolved
        • Users