0

I have the following problem. I inserted data using a random data generator into a mongodb database. Problem was I chose the wrong DB connection and now I have test data in my db. Is there any way to roll back the insert operations or delete all item that where recently inserted? Does mongodb track the time by default?

Thank you for your answers :)

Community
  • 1
  • 1
user2359459
  • 212
  • 2
  • 11
  • 1
    There is no such thing as a "rollback" ( nor is there really in many RDBMS once you already "committed" your updates ) in any default implementation of MongoDB. As with most databases, your best source of "undo" is always restoring from a backup. You can always [search for `ObjectId` values based on creation time](https://stackoverflow.com/questions/8749971/can-i-query-mongodb-objectid-by-date), but this is subjective to no other data actually being written within the same time period. In brief, generally asking "clean up my mess" is more than a little too broad. – Neil Lunn Sep 10 '17 at 06:18
  • Thank you for your answer. actually the last thing you said is quite helpful. In relational database I could always resort to just delete the entities by rownumber for example. I am sure that nothing was inserted after so I can just use your tip and delete those object id's – user2359459 Sep 10 '17 at 10:21

1 Answers1

0

So thanks to the answer of Neil Lunn, I got on the right track. While it is indeed not possible to rollback a write, I was able to detect the Creation Time and delete the data that was created in that time span.

I used this answer

Can I query MongoDB ObjectId by date?

in combination with find and remove, to remove the entities from my collections in my db.

I was able to simply copy and paste the function into the mongodb console and from there used the function on my collections.

Thank you again for pointing me in the correct direction.

user2359459
  • 212
  • 2
  • 11