Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
MySQL から MongoDB に移行したいと考えています。
MySQL では、PK は整数です。それらをObjectIDにキャストしたい
私がしようとすると:
mongo.ObjectID(theInteger)
theInteger は同じですが、結果は異なります。
どうやってやるの?
ObjectIdMongoDB の 16 進数の 24 バイト文字型です。つまり、int からキャストすることはできません。
ObjectId
MySQL データ構造を維持するためにできる最善の方法は、_idフィールドで MySQL PK を使用することです。これで問題はありません。
_id
ObjectId は mongodb の特殊なタイプですが、単に移行したい場合は、mysql の整数 ID を mongodb の '_id' に格納できます。