Remove all bookmarks

NodeBB Development
  • 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.

  • Asking again 🙄

  • What DB do you have?

  • @PitaJ said in Remove all bookmarks:

    What DB do you have?

    mongodb

  • 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

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

  • 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

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

  • @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?

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

  • @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 💃

  • 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}})
    

Suggested Topics