MongoDB Notes

When using MongoDB to store files, we have 2 collections:
1. The place where MongoDB store the file metadata: store.files
2. Ans place where MongoDB store the file content: store.chunks

Depending on the size of the file, one entry in store.files can points to many entries in store.chunks. The bigger the file, the more entry you’ll encounter.

// Show all/ list all entries from store.files

// Show only a particular entry from store.files
db.getCollection('store.files').find({ _id : ObjectId("5b02d232cbce1d07e08401c7")});

// The same can be used for store chunks.

The metadata/fields in the store.files can be expanded during query runtime (not saved into the MongoDB, only displayed during runtime)

{ $match: { _id : ObjectId("5b02d232cbce1d07e08401c7")} },
{ $addFields:{'key_reference':'1234'}}

Or we do an update into store.files which will be saved into the MongoDB

db.getCollection('store.files').updateMany({ _id : ObjectId("5b02d232cbce1d07e08401c7")},{$set:{'key_reference':'1234'}});

Leave a Reply

Your email address will not be published. Required fields are marked *

− two = 3