猫鼬模式+ nodejs

时间:2020-05-31 09:17:59

标签: node.js mongodb mongoose nosql mongoose-schema

我在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]);

data returned

但是当我想使用.name访问时,值未定义

console.log(element.opponents[0].name);

数据库架构:db

我的数据库中有一个名为“ teams”的集合。 有什么问题?我想我还没那么远...

2 个答案:

答案 0 :(得分:0)

这可能被忽略了,但是尝试...

from tkinter import *
import tkinter as tk

def scnd():
    root = tk.Tk()
    canvas = tk.Canvas(root, bg = "grey", width = 400, height = 400, relief = "groove")
    canvas.pack(expand = YES, fill="both")

    label2 = tk.Label(root, text = "Second page!", bg = "grey",fg = "white")
    canvas.create_window(100, 100, window = label2)

    button2 = tk.Button(root, text = "Open first page", bg = "blue", fg = "white", command = None)
    canvas.create_window(200, 200, window = button2)
    root.mainloop()

答案 1 :(得分:0)

db answer

我的架构不正确,进行了修改就可以了