Mongo DB gridfs references

43 views
Skip to first unread message

Martin Tumwine

unread,
Mar 11, 2018, 3:01:41 AM3/11/18
to mongodb-user
I am trying to model a user account with profile picture. Using mongo db, how do I add reference from gridfs bucket to specific user to get correct user with right profile picture?

Kevin Adistambha

unread,
Mar 29, 2018, 1:16:38 AM3/29/18
to mongodb-user

Hi Martin

GridFS is a convention designed to allow MongoDB to store files larger than 16 MB (the maximum BSON size). As such, it still works like a normal MongoDB collection (with the mandatory _id field). Note that since it is a convention, it is up to the application to make sense of the data stored in GridFS.

Typically, GridFS stores files using two collections: files and chunks (see the GridFS page for details). If you need to refer to a certain GridFS object, you can store the _id of the associated file. This _id in the files collection should be able to uniquely identify the file.

Having said that, BSON has a maximum size of 16 MB. If you find that the profile pictures + profile data you’re trying to store will never exceed this size, you may be able to just store the picture in the profile document instead.

Best regards
Kevin

Reply all
Reply to author
Forward
0 new messages