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 :)
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.
Related
I am using TingoDB and it uses all Mongodb syntax.
I have one collection where I am saving around 70K documents but when I run find query without any filter it returns only around 42K documents.
I do not know what I am doing wrong.
Please find below code,
collection().find().count(function(err, c){
console.log("count is: ",c);
console.log("err is: ",err);
});
I also checked the file where records are saved and I am sure not all records are returning.
Can somebody please help me out here.
TIA
Mangesh
You can try following things
1. Check how many records are saved in DB. Is it 70k unique records in collection.
2. Run same query using DB Client. You can run similar query using any DB Client and check if same query returns similar records.
I have a problem with MongoDB when I try to create a collection. That is, I create it and then i check it with the commands:
db.mycollection.find()
or
db.mycollection.count()
And the data comes out, however, after a certain time (minutes), the data of the collections are eliminated by themselves, that is to say they are not persisted, what is happening?
Thanks.
Our collections in MongoDB were automatically deleted/drop and we are not sure why and how. Our MongoDB is working fine for almost 10 months now, so we are really not sure what happened here.
Is there a collection expiration for MongoDB where it automatically delete the collections and its data? Also, would it be possible to retrieve the data?
Thank you in advance!
Collections do not 'drop' themselves.
Someone has run db.collection.drop() somewhere, intentionally, or accidentally.
You can set a TTL on the data inside a collection - see here however I don't think that's what has happened here.
The only way of retrieving the data would be from a backup.
Restoring a backup to a secondary database and taking a copy of the collection in question, then importing that back into your main database may be the best approach here.
... You do have backups, right?
For the last week and a half for some reason my Mongodb collections all get dumped. I can't find a reason why this is happening there doesn't seem to be a real pattern to when/why the collections get dumped. Does anyone have any insight? I'm running Mongodb version 2.6.12.
you can read this artical https://snyk.io/blog/mongodb-hack-and-secure-defaults/
also you can have a look on MongoDB database deleted automatically it should solve your problem.
I am setting up a new ElasticSearch instance using the mongo-connector python tool. The tool is working, but only imported around ~100k entries from the mongodb oplog.
However, my collections contain millions of records... Is there a way to pass all the records from each collection through the oplog without modifying the records in any way?
Following the advice of Sammaye, I solved this problem by iterating over the collection, converting to json, and posting it to the index API via curl. Thanks for the suggestion!