How to view document fields in mongo shell?

前端 未结 5 786
一个人的身影
一个人的身影 2020-12-25 14:08

Is there a way to figure out the fields/keys in a document while in mongo\'s shell? As an example, let\'s say we have a document like (pseudocode):

{
    \"m         


        
5条回答
  •  情话喂你
    2020-12-25 14:37

    A for ... in loop should do the trick:

    > var message = db.messages.findOne();
    > for (var key in message) {
    ... print(key);
    ... }
    

提交回复
热议问题