Search This Blog

Monday, December 23, 2013

The same document attribute can have different type in a single collection

Important note: This article is in relation to online MongoDB course. For more information about the course and other posts describing its content please check my main page here: M101P: MongoDB for Developers course


It is possible that multiple documents in a single collection have the same attribute of different type. In the example below the test attribute has a value number 1 on the first document and a string value in the second.
 
> db.grades.insert( {"test" : 1, "test var" : 1 } )
> db.grades.insert( {"test" : 1, "test var" : "string one" } )
>
> db.grades.find( { "test" : 1 })
{ "_id" : ObjectId("52b77870e7a1580719615d4a"), "test" : 1, "test var" : 1 }
{ "_id" : ObjectId("52b77877e7a1580719615d4b"), "test" : 1, "test var" : "string one" }

No comments:

Post a Comment