Database not updating field

Plugin Development
  • Hello everyone,

    I am trying to save a nested JSON array into my database.

    I init my database entry as following:

            Database.getObject('nodebb-plugin-europahaus-addon-spotify', function (data) {
                if (!data) {
                    //Init as default and save to database
                    data = {
                        currentTrack: "",
                        playlistSongs: [],
                        requestedSongs: [],
                        playback: false
                    }
                    Database.setObject('nodebb-plugin-europahaus-addon-spotify', data, function(err) {
            			if (err) console.error(err);
            		});
                });
    

    which adds the data perfectly fine.

    Now I want to edit one of the fields.

    Therefore, I use the following code:

                                songs = [];
                                //Add songs and information
                                tracks.forEach(function(track) {
                                    var artistsString = "";
                                    track.track.artists.forEach(function(artist) {
                                        artistsString += artist.name + ", ";
                                    });
                                    artistsString = artistsString.slice(0, -2);
                                    songs.push({
                                        track: {
                                            id: track.track.id,
                                            name: track.track.name,
                                            artists: artistsString,
                                            uri: track.track.uri
                                        }
                                    });
                                });
                                //Save data in database
                                //https://community.nodebb.org/topic/824/communicating-with-the-database/3
                                //Save JSON as string since NodeBB won't allow saving arrays
                                Database.setObjectField('nodebb-plugin-europahaus-addon-spotify', 'playlistSongs', songs, function(err) {
                                    if (err) console.error(err);
                                    callback(null, {can: true, tracks: songs});
                                });
    

    When accessing my database, no value has changed. Even when replacing the array by a simple string, no update occurs in the database.

    Thank you for your help!
    Kind regards.

  • This post is deleted!

Suggested Topics


  • 0 Votes
    3 Posts
    116 Views

    I have tried filter:composer.create and filter:composer.build and both are not firing, the only filter hook that is firing for me is filter:composer.formatting but that does not have the correct data i need (for example the catogory, etc)

    I am using nodebb v3.0

    thx for your help

  • 0 Votes
    2 Posts
    309 Views

    Hi @avan-sardar, welcome!

    find a topic based on uid and a custom session ID

    Is this a requirement? If your plugin is listening for something like action:post.save, then you can process the stripe payment.

    The action hook itself also sends the post data, which contains the pid and tid. Without more context, I am afraid I will not be able to help further.

  • 0 Votes
    5 Posts
    3k Views

    @Jenkler IMO the best example is their code!

    You could replicate and modify what in NodeBB are categories as groups (Movie/games/tv show), and what in NodeBB are topics as actual elements (a movie, a tv-series, a game). The best examples of code are their one and you can find them in /src 🙂

    In order to use these things in your plugin, check official plugins code ^^

    In my opinion is the best way to learn 😉

  • 0 Votes
    4 Posts
    2k Views

    @jiangcaiyang MySQL. I guess I need to read some articles on how MongoDB is different to get started on this.

  • 0 Votes
    2 Posts
    1k Views

    Using only the currently logged in nodebb user and minecraft player.

    Two routes needed:

    Server-only route: POST route. Requires a unique key parameter. Only the forum and the minecraft server know the key. e.g. /mc/link?key=key User route: GET route. Used to link accounts, requires a UUID and a unique player key. e.g. /mc/link/:uuid/:key

    Minimum two DB keys need:

    {uuid}:key String key, stores the unique player key for the UUID. (Could also be a hash to store additional data.) user:{uid}:uuid String key, stores the UUID linked to the user. (Could also be stored on the user hash, or made into a set for multiple linkings.) Process:

    https://www.lucidchart.com/documents/view/382333e7-c772-43b7-8061-57b3bbd83e97

    Minecraft player types a command. Server users server-only route to tell the forum it needs a registration link. Sending the unique key to verify the request is valid. Forum creates a unique player key and stores it in the DB, then sends the player key to the server. Server gives a link to the player, using the unique player key and the players' UUID. User visits link, if the user is logged in, and the uuid-key pair matches what is already in the DB, then the accounts are linked, using additional DB entries. The player key is deleted. Concerns: The player key should expire relatively quickly, like 5 minutes. Invalid requests to the user route should be monitored and blocked after a low threshold, like 3 tries. NodeBB middleware already validates the logged in user, which is why we do no additional checks. Note:

    On the last line in the diagram, I send a confirmation message, but we can't actually do this because we have not established a persistent connection. You could solve this by either having an http server on the server, or creating a socket connection to the forum.



    Or you could use Minecraft-Integration 😉