Saving and retrieving a table to a MongoDB using Pipedream.

adriangomezadriangomez Member, PRO Posts: 440

Part 1: Saving a table in GameSalad to a MongoDB Atlas instance. Attn: @Hypnorabbit & @nir3112


Comments

  • adriangomezadriangomez Member, PRO Posts: 440

    Part 2: Retrieving the table.


  • HypnorabbitHypnorabbit SingaporeMember Posts: 272

    @adriangomez you are simply awesome. I will go through this and see how I go. Thank you so much!

  • adriangomezadriangomez Member, PRO Posts: 440
    edited December 2021

    Part 3: Using Mongo Realm instead of Pipedream.

    This is the path I am going to take due to convenience and the fact that they give you more free requests. If you plan to move the MongoDB location at some point, I would stay with the original solution. Since it would just require changing the credentials at pipedream to repoint everybody to the new Mongo instance.


  • nir3112nir3112 Member, PRO Posts: 312
    edited December 2021

    @adriangomez I soooo love you right now! thank you!!

    there is some way to create login, register and logout with this methods?

  • nir3112nir3112 Member, PRO Posts: 312

    @adriangomez so I did the first video but I get TIMEOUT when I test the pipedream I re-checked all my work and its the same as on your video but I got TIMEOUT..

    any idea what can be the problem?


    thanks[=

  • nir3112nir3112 Member, PRO Posts: 312

    sorry I forgot something now its working '^_^

  • adriangomezadriangomez Member, PRO Posts: 440

    I can see if I can incorporate login/logout. What username and password are they using?

  • nir3112nir3112 Member, PRO Posts: 312

    great thanks [=

    what do you mean what username and password? username with English letters and password with letters and numbers.

    I want to send and receive unique tables to users.

    if it can be done with this methods it will be amazing and will solve me a lot of issues.

    thanks

  • adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 3,159

    I think @adriangomez might be asking what system are they logging in and out of? Do you want to manage your own user database or are yo looking to using some other 3rd party authentication system?

  • adriangomezadriangomez Member, PRO Posts: 440

    Yes exactly what I am asking.

  • nir3112nir3112 Member, PRO Posts: 312
    edited December 2021

    oh ok.. I want it to be like it was on Gamesparks. (I'm not sure what kind of authentication it was exactly)

    the user put the user name and password and hit login, then is sends to the server, confirm the data, run the login code and log him in.

    I hope I understand the question😅


    thanks for the clarification @adent42

  • adriangomezadriangomez Member, PRO Posts: 440

    @nir3112 To fix the issue you are seeing with the MacCreator, I just updated the script so you can pass the document name. For others reading this, sometimes the table name is not passed from GameSalad (in MacCreator). In my original script, I used the table name value to store the table. Now you can explicitly specify the table name you are saving via the query string.


    <URL>?documentName=<tableName>&collection=<collectionName>

  • adriangomezadriangomez Member, PRO Posts: 440

    @nir3112 Fixed: The save table script now correctly switches the value to 1 when successful. I updated the script:

    https://gist.github.com/agramonte/d1c9cdaad44232bf50f8c4fdfcc900d9

  • adriangomezadriangomez Member, PRO Posts: 440

    As requested: Part 4 shows how to use a JSON object to store username/password for authentication.

    https://youtu.be/HY5WPBydg9A

  • nir3112nir3112 Member, PRO Posts: 312
    edited December 2021


    thanks! Already tried that and it’s working[=

  • adriangomezadriangomez Member, PRO Posts: 440

    Last in the series. Just tying up some loose ends.


  • adam36021adam36021 Member, PRO Posts: 45

    Thank you for this. It's exactly what I was looking for to play around with.

  • Chris FitsimonsChris Fitsimons Member Posts: 134

    @adriangomez Hi. I looked at tutorials today and seems Realm is now App Services. Would you be able to post an update to indicate the options needed to get the same result? Thanks.


  • adriangomezadriangomez Member, PRO Posts: 440

    @Chris Fitsimons Nothing has changed. It is still the same—just the names. Sorry, I just noticed this old comment.

    @nir3112 As requested, I have posted the code I use for using a GUID per user that can be displayed to the user if needed.

    Here is what it looks like on my game:


  • adent42adent42 Key Master, Head Chef, Executive Chef, Member, PRO Posts: 3,159

    @adriangomez you are a Rock Star!

  • adriangomezadriangomez Member, PRO Posts: 440
    edited December 2022

    Hardly @adent42, but thank you anyway.

  • adam36021adam36021 Member, PRO Posts: 45

    Thanks for the wonderful resource.

    I've set up using realm & mongodb (following your third tutorial). I am successfully writing tables to the mongo database from gamesalad :)

    however, i am getting -1 request status when using the load table / get function. I think I must have missed something.

    the logs on mongodb show that the function is executing without errors, but i don't see any parsed database data in the logs there. (when i am saving / posting, i see the JSON data from gamesalad tables in the logs) -- so maybe it's a problem with my syntax?

    I've added a screenshot of my document -- the document name here is stringtst, correct? So my URL would be <url>?documentName=stringtst&collection=game

    or should i be using the tableid for the name? (id137218)


    Appreciate any insight here. I'll continue to toy with it.

  • adam36021adam36021 Member, PRO Posts: 45

    Digging further... the response from the HTTPS get request is: {} when using https://us-east-1.aws.data.mongodb-api.com/app/application-0-hrlqu/endpoint/app1/gsget?collection=game&documentName=stringtst (can click on the link and see) -- which means the function isn't returning the JSON data, i think.. so maybe it's a problem with my document names or collections?

  • adam36021adam36021 Member, PRO Posts: 45
    edited March 2023

    looks like i have found success... I changed some code in the GET function. I added async and await, that resolved my -1 error and things seem to be talking. Here's the code in case anyone needs (change application-0 to your database name):


    exports = async function(payload, response) {

        const {documentName, collection} = payload.query;

        var filter = {};

        filter["Name"] = documentName;

        // const doc = await context.services.get("mongodb-atlas").db("application-0").collection(collection).find().toArray()

         const doc = await context.services.get("mongodb-atlas").db("application-0").collection(collection).findOne(filter);

        response.setStatusCode(200);

        response.setBody(await JSON.stringify(doc));    

    };

Sign In or Register to comment.