MongoDB storing arrays of ObjectId's

后端 未结 2 898
情书的邮戳
情书的邮戳 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:02

    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.

提交回复
热议问题