MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

Perché i nuovi documenti in mongo hanno un oggetto e non un ObjectId?

Questo è cos'è un ObjectID. È semplicemente un oggetto che contiene quelle proprietà.

http://docs.mongodb.org/manual/reference/object-id/

{
    "_bsontype" : "ObjectID",
    "id" : "U\u0013[-Ф~\u001d$©t",
    "generationTime" : 1.43439e+09
}

U\u0013[-Ф~\u001d$©t è il binario di 12 caratteri stringa che viene convertita nella familiare stringa esadecimale di 24 caratteri (55107edd8e21f20000fd79a6 ) quando l'oggetto nel suo insieme è rappresentato come un valore di testo (ovvero il suo .toString viene richiamata la funzione)

In Mongoose i documenti hanno anche un .id getter che ti dà 24 caratteri esadecimali come valore di stringa.