ObjectId क्या है
ObjectId default 12-byte unique _id है जो MongoDB हर document के लिए बनाता है।
In this page:
Syntax
ObjectId()
ObjectId("hex_string")
document._id.getTimestamp()
ObjectId
एक ObjectId एक 4-byte timestamp, एक 5-byte random value, और एक 3-byte counter combine करता है, इसलिए ids machines के आर-पार unique हैं और creation time से roughly sortable हैं। getTimestamp() creation time extract करता है। _id field automatically indexed है।
Note:
ObjectIds secrets नहीं हैं; इन्हें security tokens की तरह इस्तेमाल न करें।
उदाहरण: ObjectId
test> const id = new ObjectId()
test> id
ObjectId('65a1b2c3d4e5f60718293a4d')
test> id.getTimestamp()
ISODate('2024-01-12T14:30:11.000Z')
test> typeof id.toString()
string
test> ObjectId.isValid("65a1b2c3d4e5f60718293a4d")
true
⚠️ Run this in your own terminal or Node.js environment.
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
- ObjectIds को strings की तरह compare करना
- यह मान लेना कि ObjectIds sequential integers हैं
- इन्हें unguessable tokens की तरह इस्तेमाल करना
चैप्टर सारांश
- ObjectId एक 12-byte unique id है
- इसमें एक timestamp है
- getTimestamp() time पढ़ता है
- _id automatically indexed है
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: