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
    2 Posts
    352 Views

    I suggest using user.updateProfile to make these changes, since it updates the necessary sorted sets for email/fullname.

    You can use the same function to update the picture url as well.

    await User.updateProfile(callerUid, { uid: targetUid, uploadedpicture: url, picture: url, }, ['uploadedpicture', 'picture']);
  • 0 Votes
    18 Posts
    2k Views

    @gotwf said in Plugin development 2021 updated - environment and dev workflow - request:

    Like all powerful tooling, Emacs doe have its learning curve. But it is free and pretty much does any and everything.

    .. and even coffee. 😉

    As does vim with a couple of bundles. This is what I'm used to and also working with on nodebb.

    It's just that you have to pick one and try it or learn how to do it.

  • 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
    6 Posts
    2k Views

    @Fez-Vrasta You have to include it. e.g. var SocketIO = require('./socket.io');

    I'm not sure if there is an option for per widget client js. I put it in my main client.js in my plugin.json.

  • 0 Votes
    1 Posts
    945 Views

    Hi! I'm trying to make another SSO plugin, but the difference is: i want user to fill missing fields (like email) after external authentication but before user is created in the forum.

    The only good solution i see is to override successReturnToOrRedirect andfailureRedirect fields to custom routes (https://github.com/NodeBB/NodeBB/blob/master/src/routes/authentication.js#L60), which are handled by plugin itself, to render input forms and logic. So i think it would be nice to extend login strategy with success/fail routes and use them if specified.

    I would like to hear opinion about my idea. If it is good enough i think i can create pull request.