MongoDB storing arrays of ObjectId's MongoDB storing arrays of ObjectId's mongodb mongodb

MongoDB storing arrays of ObjectId's


I would definitely go with the first approach, storing the ObjectIds directly. This saves space, as ObjectId is 12 bytes whereas the second approach string is 24 bytes.

Also, if the ObjectIds are used to fetch the objects later, storing as ObjectId saves some hassle.


Unless you have a good reason not to, store them as an array of ObjectIds. It's more compact (12 bytes vs. 24) and it more accurately reflects what's stored. It can also enable driver-level support for following ObjectId references.