mongodb print json without whitespace i.e. unpretty json

后端 未结 6 1127
礼貌的吻别
礼貌的吻别 2020-12-30 19:52

I\'m using mongodb 2.2.0 and am trying to print json in a single line as opposed to \"pretty\" printing using printjson() or find().pretty(). i.e.

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-30 20:26

    Try print(tojson()) - there's an example of printing using a cursor in the MongoDB docs.

        var myCursor = db.inventory.find( { type: 'food' } );
        var myDocument = myCursor.hasNext() ? myCursor.next() : null;
    
        if (myDocument) {
            var myItem = myDocument.item;
            print(tojson(myItem));
        }
    

提交回复
热议问题