Old MongoDB with 10 character _ids?

Hello,

Im reviving an older (4 - 5 years old) mongodb. I have it running on Atlas and am able to do general queries ( find({}) ) etc. However, Im finding that the _id in these records are only 10 characters long DhIGSRROpQ and when I try to use it in the Node driver Im getting BSONError: Argument passed in must be a string of 12 bytes or a string of 24 hex characters or an integer.

From what I’m finding online, that doesn’t appear to be a valid ObjectId. Did MongoDB change how they handle OjbectIds over the last few years? And if so, is there anything that I can do to be able to use my db as is?

If you need more information in order to lend a hand, Im happy to provide.

Thank you in advance,

Peter

Are you sure the existing _id is an ObjectId ?

The _id could just be a string.

It’s was a string. In the Node driver, the default is that its an ObjectId. So you have to let the query know its a string with

interface StringIdDocument {
    _id: string;
    [keys: string]: any
}
const customerCol = db.collection<StringIdDocument>("_users")

This is working.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.