Skip to content

Instantly share code, notes, and snippets.

@isa424
Created November 4, 2017 13:57
Show Gist options
  • Select an option

  • Save isa424/ba932c276a88bc9d6d6f367e34bbc226 to your computer and use it in GitHub Desktop.

Select an option

Save isa424/ba932c276a88bc9d6d6f367e34bbc226 to your computer and use it in GitHub Desktop.
const conn = new Mongo("127.0.0.1:27017");
const db = conn.getDB("cubicl");
db.auth("app", "12345678");
var todos = db.todos.find({"category": {$ne: null}});
todos.forEach(function(todo) {
var category = todo.category;
var exists = db.todo_categories.find({_id: category}).count();
if (!exists) {
db.todos.updateOne({_id: todo._id}, {$set: {category: null}});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment