【发布时间】:2016-03-11 23:01:16
【问题描述】:
大家好,我是 nodejs 新手,我正在尝试访问 json 中的对象并从 moongoose 获取输出。
这是我使用的代码:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
mongoose.connect('hidden');
var userSchema = new Schema({
name: String,
link: String
});
var User = mongoose.model('User', userSchema);
// the schema is useless so far
// we need to create a model using it
User.find({}, function(err, users) {
if (err) throw err;
// object of all the users
console.log(users);
});
这是输出:
[ { __v: 0,
link: 'google.com',
name: 'google',
_id: 5665589cb813b33c385edec2 },
{ link: 'yahoo.com',
name: 'yahoo',
_id: 56655f3facc5c2203ccb5c71 } ]
如何将“google.com”和“yahoo.com”放入简单的单个变量中?
提前致谢。 任何帮助将不胜感激。
【问题讨论】: