# Collection creation and removal after restored from full logical backup - Mongodb

**URL:** <https://forums.percona.com/t/collection-creation-and-removal-after-restored-from-full-logical-backup-mongodb/36089>\
**Category:** MongoDB\
**Created:** [January 11, 2025, 12:04pm UTC](https://forums.percona.com/t/collection-creation-and-removal-after-restored-from-full-logical-backup-mongodb/36089 "2025-01-11T12:04:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gowtham-ji](https://avatars.discourse-cdn.com/v4/letter/g/3d9bf3/32.png) [@gowtham-ji](https://forums.percona.com/u/gowtham-ji)\
**Post date:** [January 11, 2025, 12:04pm UTC](https://forums.percona.com/t/collection-creation-and-removal-after-restored-from-full-logical-backup-mongodb/36089/1 "2025-01-11T12:04:11Z")

</div>

Hi

**Before full logical backup database status**

admin 13.34 MiB  
config 3.61 MiB  
doublecollection 94.25 MiB  
pitr 95.52 MiB  
restore 259.36 MiB  
restore-test-1 94.63 MiB  
singlecollection 40.00 KiB  
test1db 306.50 MiB  
withoutcollections 40.00 KiB

**after Full Logical backup I created collection1 db and added ducuments to the collection1 under collection1 db**

[direct: mongos] collection1\> show collections  
collection1

**collection1 size:**

sharded: false,  
size: 426,  
count: 9,  
numOrphanDocs: 0,  
storageSize: 36864,  
totalIndexSize: 36864,  
totalSize: 73728,  
indexSizes: { _id_: 36864 },  
avgObjSize: 47,  
ns: ‘collection1.collection1’,  
nindexes: 1,  
scaleFactor: 1

**database status**

[direct: mongos] test\> show dbs  
admin 13.34 MiB  
**collection1 72.00 KiB**  
config 3.61 MiB  
doublecollection 94.25 MiB  
pitr 95.52 MiB  
restore 259.36 MiB  
restore-test-1 94.63 MiB  
singlecollection 40.00 KiB  
test1db 306.50 MiB  
withoutcollections 40.00 KiB

**After restored from full logical backup database status**

[direct: mongos] test\> show dbs  
admin 13.34 MiB  
**collection1 72.00 KiB**  
config 3.61 MiB  
doublecollection 94.25 MiB  
pitr 95.52 MiB  
restore 259.36 MiB  
restore-test-1 94.63 MiB  
singlecollection 40.00 KiB  
test1db 306.50 MiB  
withoutcollections 40.00 KiB

[direct: mongos] test\> use collection1  
switched to db collection1  
[direct: mongos] collection1\> show collections

[direct: mongos] collection1\>

I could see collection1 db size is 72.00 KiB even I couldn’t see any collections under collection1 and this is the expected behaviour of logical backup.

If I know the collection name created under collection1 db, I will bring back the removed collection again using the command - **db.createCollection(“collection1”)**

and if I don’t want, I will delete the collection permanently the same way using the command **db.dropCollection()** or **db.dropDatabase()** after bring back the removed collection.

**what if I don’t know the collection name, how I can bring back the removed collection and how I can delete the removed collection permanently ?**

---

<div class="post-metadata">

**Author:** ![anil.joshi](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/anil.joshi/32/13100_2.png) [@anil.joshi](https://forums.percona.com/u/anil.joshi)\
**Post date:** [January 13, 2025, 11:43am UTC](https://forums.percona.com/t/collection-creation-and-removal-after-restored-from-full-logical-backup-mongodb/36089/2 "2025-01-13T11:43:23Z")

</div>

@gowtham-ji

> **what if I don’t know the collection name, how I can bring back the removed collection and how I can delete the removed collection permanently ?**

Sorry I didn’t get what you exactly meant by deleting the removed collection. If you dropping a collection " **db.collection.drop()**" it will be a permanent delete of the schema/indexes. There is no need to do any further action. Can you elaborate the context ?

Additionally, if you removed the collection the only way to restore it from the backup. Well you have the feasibility to just restore the schema/index (“\ ***.metadata.json** ”) without any data.

E.g, restoring only schema.

`rsync --recursive --include="*.json" --exclude='*.bson' /backups/ /backups2/`

```auto
ls -lh /backups2/test
total 4.0K
-rw-r--r--. 1 root root 324 Jan 1 14:23 test1.metadata.json

```

`mongorestore -uroot -proot --db test /backups2/test/`

Moreover, you can also track the changes (Create/Delete) in the **oplog.rs** collection which can be used for the PITR purpose.

```auto
rs0 [direct: primary] local> **db.oplog.rs.find(**{
... "o.drop": "test1"
... }).sort({$natural: -1})
[
  {
    op: 'c',
    ns: 'test.$cmd',
    ui: UUID('b272134f-aec3-4575-a1e7-9efdeba111b4'),
    o: { drop: 'test1' },
    o2: { numRecords: 0 },
    ts: Timestamp({ t: 1736768019, i: 1 }),
    t: Long('1'),
    v: Long('2'),
    wall: ISODate('2025-01-13T11:33:39.909Z')
  }
]

```

Since its a capped collection so better to have a regular backup policy of this collection “oplog.rs” for the Recovery purpose.

For restorations - **-oplogReplay** can be used with the mongorestore command.

- List item

> **[mongorestore - MongoDB Database Tools](https://www.mongodb.com/docs/database-tools/mongorestore/#std-option-mongorestore.--oplogReplay)**
>
> mongorestore is a database tool that loads data from either a binary database dump created by mongodump or the standard input into a MongoDB instance.

Let me know if this is what you looking for ?

---

<div class="post-metadata">

**Author:** ![gowtham-ji](https://avatars.discourse-cdn.com/v4/letter/g/3d9bf3/32.png) [@gowtham-ji](https://forums.percona.com/u/gowtham-ji)\
**Post date:** [January 13, 2025, 11:54am UTC](https://forums.percona.com/t/collection-creation-and-removal-after-restored-from-full-logical-backup-mongodb/36089/3 "2025-01-13T11:54:09Z")

</div>

> [@gowtham-ji](#):
>
> collection1 72.00 KiB

Hi @anil.joshi

For the collection1 data base - **collection1 72.00 KiB** I could see still **72.00 KiB** space occupied by **collection1 72.00 KiB** database even there is no data or collection under the collection database. How can I remove those **72.00 KiB** space completely?

 ![collection1 db size status](https://us1.discourse-cdn.com/flex019/uploads/percona1/original/3X/1/a/1a6c821e29fcdd8649c8fbe59ee13bb139192071.png)

---

<div class="post-metadata">

**Author:** ![anil.joshi](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/anil.joshi/32/13100_2.png) [@anil.joshi](https://forums.percona.com/u/anil.joshi)\
**Post date:** [March 14, 2025, 4:22pm UTC](https://forums.percona.com/t/collection-creation-and-removal-after-restored-from-full-logical-backup-mongodb/36089/4 "2025-03-14T16:22:09Z")

</div>

@gowtham-ji

It was interesting to see what version of MongoDB you are using. I tried with different version but don’t see such behaviour.

E,g,

```auto
rs0 [direct: primary] test> show dbs
admin 80.00 KiB
config 116.00 KiB
local 1.94 MiB
test 1.67 MiB

```

When i dropped the collection there is no resemblance of either the table size or the database itself.

```auto
rs0 [direct: primary] test> db.users.drop()
true

```

```auto
rs0 [direct: primary] admin> show dbs
admin 80.00 KiB
config 128.00 KiB
local 2.37 MiB

```
