【发布时间】:2020-09-18 16:19:16
【问题描述】:
我是 mongodb 的新手,我遇到了麻烦 我无法从我的 mongo 数据库中获取数据
const mongoose = require('mongoose');
const Team = new mongoose.Schema({
name: String,
});
const MatchsSchema = new mongoose.Schema({
begin_at: Date,
number_of_games: Number,
name: String,
tournament: {
name: String,
},
opponents: {
type: [Team],
default: undefined
},
});
const Matchs = mongoose.model('matchs', MatchsSchema);
module.exports = Matchs;
我正在尝试使用此代码进行访问,女巫返回我的“数据”:
console.log(element.opponents[0]);
但是当我想用 .name 访问时,值是未定义的
console.log(element.opponents[0].name);
数据库架构:db
我的数据库中有一个名为“teams”的集合。 有什么问题?我想我没那么远......
【问题讨论】:
标签: node.js mongodb mongoose nosql mongoose-schema