Remove all bookmarks


  • Plugin & Theme Dev

    How can i remove all bookmarks from all users?
    We use it for favourites on the past and want to begin use it as real bookmarks but we have hundreds saved, so i need a database command to clean them.


  • Plugin & Theme Dev

    Asking again 🙄


  • Global Moderator

    What DB do you have?


  • Plugin & Theme Dev

    @PitaJ said in Remove all bookmarks:

    What DB do you have?

    mongodb


  • Global Moderator

    Paste the following into a file named removeBookmarks.js in your base nodebb directory and then run node ./removeBookmarks.js

    // removeBookmarks.js
    
    'use strict';
    /*globals require, console, process */
    
    var nconf = require('nconf');
    var async = require('async');
    var fs = require('fs');
    
    nconf.file({
        file: 'config.json'
    });
    
    var db = require('./src/database');
    
    db.init(function(err) {
      if (err) {
        console.log("NodeBB could not connect to your database. It returned the following error: " + err.message);
        process.exit();
      }
    
      db.getSortedSetRange('topics:tid', 0, -1, function(err, tids){
        async.each(tids, function(tid, next) {
          db.delete('tid:' + tid + ':bookmarks', next);
        });
      });
    });
    

    Some stolen from @baris


  • Plugin & Theme Dev

    @PitaJ said in Remove all bookmarks:

    Paste the following into a file named removeBookmarks.js in your base nodebb directory and then run node ./removeBookmarks.js

    // removeBookmarks.js
    
    'use strict';
    /*globals require, console, process */
    
    var nconf = require('nconf');
    var async = require('async');
    var fs = require('fs');
    
    nconf.file({
        file: 'config.json'
    });
    
    var db = require('./src/database');
    
    db.init(function(err) {
      if (err) {
        console.log("NodeBB could not connect to your database. It returned the following error: " + err.message);
        process.exit();
      }
    
      db.getSortedSetRange('topics:tid', 0, -1, function(err, tids){
        async.each(tids, function(tid, next) {
          db.delete('tid:' + tid + ':bookmarks', next);
        });
      });
    });
    

    Some stolen from @baris

    sorry for the late reply, i´m talking about this bookmarks and i think your code if for user last-read-position in the thread

    0_1473472586076_Screenshot_1.png


  • Plugin & Theme Dev

    i can remove them with
    db.objects.remove({_key:"uid:XXX:favourites"});

    works ok for the user but bookmark count number still shown on the posts dropdown


  • Community Rep

    This is everything i think. (untested)

    // Remove the list of favorited posts from all users.
    db.objects.remove({_key: /^uid:\d+:favourites$/})
    // Remove the list of users who favourited the post from all posts.
    db.objects.remove({_key: /^pid:\d+:users_favourited$/})
    // Remove the favorite count from all posts.
    db.objects.update({_key: /^pid:\d+$/}, {$set: {reputation: 0}})
    

    I used a regex with start and end characters to avoid matching any objects that may have been created by a plugin.


  • Plugin & Theme Dev

    @yariplus said in Remove all bookmarks:

    This is everything i think. (untested)

    // Remove the list of favorited posts from all users.
    db.objects.remove({_key: /^uid:\d+:favourites$/})
    // Remove the list of users who favourited the post from all posts.
    db.objects.remove({_key: /^pid:\d+:users_favourited$/})
    // Remove the favorite count from all posts.
    db.objects.update({_key: /^pid:\d+$/}, {$set: {reputation: 0}})
    

    I used a regex with start and end characters to avoid matching any objects that may have been created by a plugin.

    thank you very much
    about the thrid command, bookmarks doenst have to do with reputation so i guess is enough with first two?


  • Community Rep

    It's strange. post.reputation is actually the bookmark count. The reputation count is (post.upvotes - post.downvotes)


  • Plugin & Theme Dev

    @yariplus said in Remove all bookmarks:

    It's strange. post.reputation is actually the bookmark count. The reputation count is (post.upvotes - post.downvotes)

    lol allright :dancer:


  • Plugin & Theme Dev

    In case someone need to do this too, the correct commands are

     // Remove the list of favorited posts from all users.
     db.objects.remove({_key: /^uid:\d+:favourites$/})
    // Remove the list of users who favourited the post from all posts.
     db.objects.remove({_key: /^pid:\d+:users_favourited$/})
    // Remove the favorite count from all posts.
    db.objects.updateMany({"_key":/post:[0-9]+/g},{$set: {reputation: 0}})
    

Log in to reply
 

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.