Empty all the rows in Orient-DB

流过昼夜 提交于 2019-12-01 20:41:04

问题


Is there are a command to flush/empty all the classes/clusters in Orient-DB.

Like Empty function in MySQL.

P.S : Searched here as well : https://github.com/orientechnologies/orientdb/wiki/Console-Commands


回答1:


There is no such command available.

If you want to preserve the meta data of the classes, you can use the truncate command (same as most RDBMS). It deletes all records from all clusters of the specified class (but keeps the meta data about the class):

truncate class <yourclass>

If you want to truncate all custom classes (so excluding the OrientDB classes, which all start with capital "O"), you can use this script:

  connect plocal:<yoururl> <yourusername> <yourpassword>;
  js var result = db.query('select name from (select expand(classes) from metadata:schema) where name.charAt(0) <> "O"'); 
  for (var i = 0; i < result.length; i++) { 
    var className = result[i].getRecord().field('name'); 
    db.command('truncate class ' + className);
  }; 
  result.length + ' classes truncated'; 
  end;
  exit

Save this script as truncate-all.osql. To execute this script, go to ORIENTDB_HOME/bin directory and execute:

$ ./console.sh truncate-all.osql


来源:https://stackoverflow.com/questions/28134059/empty-all-the-rows-in-orient-db

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!