互換性
次の環境でホストされる配置には ObjectId.toString() を使用できます。
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
例
次の例:
新しい
ObjectId()を生成し、変数myObjectIdに保存します。Creates a string representation of
myObjectIdusing thetoString()method.string 表現を変数
myObjectIdStringに保存します。
Run the following commands in mongosh:
myObjectId = ObjectId("507c7f79bcf86cd7994f6c0e") myObjectIdString = myObjectId.toString()
この操作では、次の string が返されます。
507c7f79bcf86cd7994f6c0e
myObjectIdStringの型を確認するには、 typeof JavaScript 演算子を使用します。
typeof myObjectIdString
この操作では、以下を返します。
string