mongoDB : Creating An ObjectId For Each New Child Added To The Array Field

后端 未结 2 1198
耶瑟儿~
耶瑟儿~ 2020-12-31 16:48

mongodb 2.1.4(The Node Driver)

I\'m currently trying to create a new ObjectID for each message I insert into an array(the array being a subdocument).

I figur

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 17:14

    Sorry for the breech of protocol but I do no have enough rep to comment on the main thread.

    I have been looking at how to generate a JSON insert using ObjectID() and in my travels have found that this solution is not very good for indexing. The proposed solution has _id values that are strings rather than real object IDs - i.e. "56a970405ba22d16a8d9c30e" is different from ObjectId("56a970405ba22d16a8d9c30e") and indexing will be slower using the string. The ObjectId is actually represented internally as 16 bytes.

提交回复
热议问题