Database not updating field



  • 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!

Log in to reply
 

Suggested Topics

  • 7
  • 3
  • 1
  • 5
  • 2
| |