我正在尋找一種解決方案來創建一個唯一的字串來創建一個檔案名。我意識到那是ObjectId()一個id.$oid獨特的字串。但我不確定。作業成功了嗎?
示例代碼:
List<FileObject> generateFileName(List<FileObject> files) {
return files.map((e) => e..updateName(ObjectId().$oid)).toList();
}
class FileObject {
FileObject({this.name, this.path, this.url, this.type});
String? name;
String? path;
String? url;
String? type;
void updateName(String? name) => this.name = name;
}
- 作業是否
ObjectId().$oid完美? - 有沒有更好的辦法?
uj5u.com熱心網友回復:
AnObjectId應該是唯一的,因為它是一個 12 位元組 BSON 型別的十六進制字串,其中包括基于其創建時間的隨機化。
來源/參考:https ://www.knowledgehut.com/blog/web-development/objectid-in-mongodb
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/526231.html
標籤:镖蒙戈飞镖飞镖服务器
