MongoDB Collections Unexpected Deletion/Drop - mongodb

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?

Related

Mongo DB remove recently inserted items

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.

Collections are deleted by themselves in MongoDB

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.

Mongodb keeps dropping all my collections randomly

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.

Is It A Good Idea to use oplog for versioning in MongoDB

My program uses MongoDB and It needs to log all insert, update and delete operations and prints it to user. I look at the mongo oplog and it seems it provides the necessary functionality. As in advantage, it allows to see all changes made outside of my program. I see one problem that it is capped and deletes old entries, but I want to keep all history. Though I think it can be solved by setting a large oplog size and I hope the space will not be an issue.
Are there other problems with this approach?
One of MongoDB's solutions architects has written a blog post about this. Essentially you can query the oplog and copy the data to a new collection. I guess that means its not a terrible idea though I can't comment on whether it's a good idea.

MongoDB. Keep information about sharded collections when restoring

I am using mongodump and mongorestore in a replicated shard cluster in MongoDB 2.2. to get a backup and restore it.
First, I use mongodump for creating the dump of all the system, then I drop a concrete collection and restore it using mongorestore with the output of mongodump. After that, the collection is correct (the data it contains is correct and also the indexes), but the information about if this collection is sharded is lost. Before dropping it, the collection was sharded. After the restore, however, the collection was not sharded anymore.
I was wondering then if a way of keeping this information in backups exist. I was thinking that maybe sharded information for collection is kept in the admin database, but in the dump, admin folder is empty, and using show collections for this database I get nothing. Then I thought it could be kept in the metadata, but this would be strange, because I know that, in the metadata, the information about indexes is stored and indexes are correctly restored.
Then, I would like to know if it could be possible to keep this information using instead of mongodump + mongorestore, filesystem snapshots; or maybe still using mongodump and mongorestore but stopping the system or locking writing. I don't thing this last option could be the reason, because I am not performing writing operations while restoring even not being locking it, but just to give ideas.
I also would like to know if anyone is completely sure about if it is the case that this feature is still not available in the current version.
Any ideas?
If you are using mongodump to back up your sharded collection, are you sure it really needs to be sharded? Usually sharded collections are very large and mongodump would take too long to back it up.
What you can do to back up a large sharded collection is described here.
The key piece is to back up your config server as well as each shard - and do it as close to "simultaneously" as possible after having stopped balancing. Config DB is small so you should probably back it up very frequently anyway. Best way to back up large shards is via file snapshots.