Answer the question
In order to leave comments, you need to log in
How to store JSON in MongoDB while maintaining associations?
I'm trying to migrate a sql dump to MongoDB. I overtook this case in json, slightly changed the structure, and I try to save it from the file to the database. The problem is that the id of the records in the dump were purely numeric, and as such, they are not suitable as an ObjectId . And I need to save links between different types of posts and categories. Relationships are set precisely through these numerical IDs.
I tried to set _id at the time of saving in this form:
new ObjectId(x.toString(2))
или
new ObjectId(x.toString(16))
или просто
x.toString(2)
Argument passed in must be a single String of 12 bytes or a string of 24 hex characters
Answer the question
In order to leave comments, you need to log in
Or maybe there are other options?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question