search

Home  >  Q&A  >  body text

Should I use string or objectid for non-primary key IDs in mongodb?

{
    _id:ObjectId,
    otherID:String
}
{
    _id:ObjectId,
    OtherID:ObjectId
}

What’s the difference?

过去多啦不再A梦过去多啦不再A梦2875 days ago766

reply all(3)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-02 09:27:26

    Please use ObjectId, various operations are more convenient than strings

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-02 09:27:26

    I have made a more comprehensive explanation about ObjectId, you can refer to the article.
    If you don’t want to read it all, the answer to this question is in the Q&A section at the end.

    reply
    0
  • PHP中文网

    PHP中文网2017-05-02 09:27:26

    ObjectId is easier to generate in a sharded environment... and the default _id key is an ObjectId object..

    reply
    0
  • Cancelreply