How to mention datatypes of fields in documents???

18 views
Skip to first unread message

Sunita Kumari

unread,
Jul 9, 2014, 8:47:02 AM7/9/14
to mongod...@googlegroups.com
how to mention datatypes while  creating documents in collection.Suppose if insert age as 12 in one document..and twelve in another document..how to avoid this happening????

William Berkeley

unread,
Jul 10, 2014, 10:00:55 AM7/10/14
to mongod...@googlegroups.com
Hi Sunita. MongoDB does not have schemas to enforce datatype restrictions, so enforcing these restrictions is up to your application. However, for many languages there are ODM (object-document mapper) libraries that will handle translation between objects in code and objects in the database and sometimes will allow you to construct schemas with datatypes for different fields that the ODM code will enforce. I've included a list of a few popular MongoDB ODMs:
  • mongoosejs (Node.js)
  • Doctrine (PHP)
  • Morphia (Java)
  • Mongoid (Ruby)
If you've loaded data and want to check that the types are as expected, look at the $type operator.

-Will
Reply all
Reply to author
Forward
0 new messages