Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › Firebase: How to "add" instead of "set".

Tagged: 

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #22237

    Eric

    Hello,

    I’m looking at using Firebase but I’m having trouble getting it to work as I would like.

    From what I understand from Google’s documentation, there are two ways to add data to the database, set() and add(). Let’s say I have the following database structure:

    users: {
       userKey: {
          c1: {
             v1: true
          }
       }
    }

     

    and I want to add as a child of c1, {v2: true}. However, when I use setUserValue(“c”, {v2: true}), it completely recreates c1, deleting anything else that might be in there. I would rather have something like “addUserValue(“c”, {v2: true})” that would then give me:

    users: {
       userKey: {
          c1: {
             v1: true
             v2: true
          }
       }
    }

     

    I can’t find anything in the documentation. How would I go about accomplishing this?

    Thank you,
    Eric

    #22238

    Edward

    Hey!

     

    Using either .setValue or .setUserValue, I have come across this, try;

     

    setUserValue(“c/”, {v2: true})

    (note the added ‘/’), this is directing your data write down into the path, instead of just recreating it 🙂

     

    Thanks

    #22243

    Eric

    Hello Edward,

    Unfortunately, I’m not getting this to work. If I run:

    database.setUserValue("c/", {v2: true})
    database.setUserValue("c/", {v3: true})

    The database simply reads (note the overwriting still happens):

    users: {
       userKey: {
          c: {
             v3: true
          }
       }
    }

    Does your solution work for you when run? If so, can you provide some code because I certainly can’t get it to work.

    Thank you,
    Eric

    #22244

    Edward

    Hi Eric,

     

    Yes I have multiple key/value pairs which are updated/edited, i.e;

     

    
        function adminAmendNewUserHours(totalAllowance, adminAmendWeeklyHours) {
                firebaseDb.setValue(
    "users" + "/" + "MYUSERNAME" + "/" + "allowances" + "/" + "2019" + "/" + "total", totalAllowance)
            
        }

    In the example code of mine, the path may be quite long, but when it comes down to it, I am updating the value of “total”, with “totalAllowance” (a variable), although nested in this area, are other objects, JSON items ect – and it only effects my intended,

     

    If you joined the felgo stack group you can find me there and ping me maybe we can go into a bit more depth!

     

    Thanks

    Edward

Viewing 4 posts - 1 through 4 (of 4 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded