5

It is understandable that since the database is schema less we are not able to But if we take one record e.g db.collectionname.findOne(), it is not schema less. It has fixed attributes. How do I get that attribute less ?

1 Answer 1

9

the code:

> db.mycoll.insert( {num:3, text:"smth", date: new Date(), childs:[1,2,3]})
> var rec = db.mycoll.findOne();

> for (key in rec) { 
    var val = rec[key];
    print( key + "(" + typeof(val) + "): " + val ) }

will print:

_id(object): 4e2d688cb2f2b62248c1c6bb
num(number): 3
text(string): smth
date(object): Mon Jul 25 2011 15:58:52 GMT+0300
childs(object): 1,2,3

(javascript array and date are just "object")

This shows "schema" of only top level, if you want to look deeper, some recursive tree-walking function is needed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.