如何让Meteor shell显示整个对象?

时间:2015-10-05 02:13:24

标签: meteor

当我在meteor shell中输入时,这就是我所看到的:

> Meteor.users.find({username: "test"}).fetch()
[ { _id: 'rKAAq3koteTGQZyey',
    createdAt: Mon Oct 05 2015 15:24:55 GMT+1300 (NZDT),
    services: { password: [Object] },
    username: 'test',
    emails: [ [Object] ],
    profile: { services: [Object] } } ]
> 

我希望了解[Object]

中的内容

我真的很讨厌不得不把所有东西都变成JSON:

How do I get meteor shell output to be more verbose?

> JSON.stringify(Meteor.users.find().fetch(), undefined, 2);
'[\n  {\n    "_id": "rAw9EHxEdMFho2yvc",\n    "createdAt": "2015-10-05T01:51:18.103Z",\n    "services": {\n      "password": {\n        "bcrypt": "$2a$10$UN5JtVvFtgZ4rfuwSSGPDOtMRIUBVR9QCSWvEOPAFkTqteQhCO8wi"\n      },\n      "resume": {\n        "loginTokens": [\n          {\n            "when": "2015-10-05T01:51:50.198Z",\n            "hashedToken": "KmmMczQ6R6kwkQWuQdRR8wlrvSwNW12LsGDsoeDfZ3Q="\n          }\n        ]\n      }\n    },\n    "username": "admin",\n    "emails": [\n      {\n        "address": "admin@example.com",\n        "verified": false\n      }\n    ]\n  },\n  {\n    "_id": "PxYZ5ACGgYC7ZJXnB",\n    "createdAt": "2015-10-05T01:51:18.230Z",\n    "services": {\n      "password": {\n        "bcrypt": "$2a$10$CUqmJq8yhbvWSIEQBUwPv.dGLx16kckhL3Xz2eGl8QyyI.gIiFF8q"\n      }\n    },\n    "username": "alex",\n    "emails": [\n      {\n        "address": "alex@example.com",\n        "verified": false\n      }\n    ]\n  },\n  {\n    "_id": "ZpyAMTdwNzeBMLZuc",\n    "createdAt": "2015-10-05T01:51:18.342Z",\n    "services": {\n      "password": {\n        "bcrypt": "$2a$10$BUs2mCOXxmQPBvFpkUgIWO8RCsJh9OQphtMc5Eg7Fb2S1yIBG2NFu"\n      }\n    },\n    "username": "ana",\n    "emails": [\n      {\n        "address": "ana@example.com",\n        "verified": false\n      }\n    ]\n  },\n  {\n    "_id": "MqipzbhRpJmv5sqww",\n    "createdAt": "2015-10-05T01:51:18.534Z",\n    "services": {\n      "password": {\n        "bcrypt": "$2a$10$Ltgla017NQkJDlvlltQ1TOjNQ7FUv92kgOUa6bCh2lwRQpqsMRr.i"\n      }\n    },\n    "username": "jose",\n    "emails": [\n      {\n        "address": "jose@example.com",\n        "verified": false\n      }\n    ]\n  },\n  {\n    "_id": "T8ggaDgaSmWANbDmk",\n    "createdAt": "2015-10-05T01:51:18.678Z",\n    "services": {\n      "password": {\n        "bcrypt": "$2a$10$C7Wg4l87ALPaq/8Uhjo8FOnCBhw9n5qoyEkJkq9FzxM5./XU8NzSa"\n      }\n    },\n    "username": "anthony",\n    "emails": [\n      {\n        "address": "anthony@example.com",\n        "verified": false\n      }\n    ]\n  },\n  {\n    "_id": "rKAAq3koteTGQZyey",\n    "createdAt": "2015-10-05T02:24:55.162Z",\n    "services": {\n      "password": {\n        "bcrypt": "$2a$10$aYBlVYJhl1vS8iDYF6nuUObYDTK6prfUtaqL9ao0Hq7uX863IyTa."\n      }\n    },\n    "username": "test",\n    "emails": [\n      {\n        "address": "test@example.com",\n        "verified": false\n      }\n    ],\n    "profile": {\n      "services": [\n        {\n          "hdrPhotos": 100\n        }\n      ]\n    }\n  }\n]'
> 

3 个答案:

答案 0 :(得分:1)

只是做:

$ meteor mongo

这将使您可以直接访问mongo db。然后你可以这样做:

db.users.findOne({username: "test"})

并且你将为你准备好整个对象。

答案 1 :(得分:0)

要获得良好的格式,请执行

JSON.stringify(Meteor.users.find().fetch(), undefined, 2);

答案 2 :(得分:0)

function printObj(obj){
  console.log( JSON.stringify(obj, null, 2));
}

然后:

printObj(Meteor.users.find().fetch())

您的输出不在shell中,而是在服务器日志中,但会返回您想要的所有数据。