MongoDB storing arrays of ObjectId's

后端 未结 2 900
情书的邮戳
情书的邮戳 2021-02-07 05:31

In my database I have to store an array of object ids. What should I use? Something like this:

[ObjectId(\"50350e12a36feb1be6000364\"), ObjectId(\"57350e12a37fef         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-07 06:19

    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.

提交回复
热议问题