Conversion from String to MongoDB ObjectID

前端 未结 5 1545
情深已故
情深已故 2021-01-20 09:18

I tried converting my String ID to MongoDB ObjectID

public class relevancy_test extends  Object implements Comparable {
    public static voi         


        
5条回答
  •  野性不改
    2021-01-20 09:51

    ObjectId is a 12-byte BSON type

    Here your string "8001_469437317594492928_1400737805000" is not 12 byte BSON type. so update according to ObjectId

    To generate a new ObjectId using the ObjectId() constructor with a unique hexadecimal string:

    var stringObjectId = ObjectId("507f191e810c19729de860ea");
    

    Please make string correct to convert string to objectId.

提交回复
热议问题