英文:
How can I make tree schema in MongoDB service using Node js and express
问题
我想在Angular 8中创建一个mat-tree,并且数据应该来自MongoDB数据库。为此,我需要在后端服务器中创建一个树形结构的模式,然后将数据放入该模式并从该模式中检索数据。到目前为止,我已经从本地数据创建了mat-tree,并在我的后端服务器中创建了一个树模型,如下所示:
const mongoose = require('mongoose');
const Schema = mongoose.Schema
const treeSchema = new Schema({
name: String,
parent: {
type: Schema.Types.ObjectId,
ref: 'Node'
},
children: [{
type: Schema.Types.ObjectId,
ref: 'Node'
}],
ancestors: [{
type: Schema.Types.ObjectId,
ref: 'Node'
}]
})
module.exports = mongoose.model('Node', treeSchema)
我不知道如何使用API服务将数据放入和检索数据从这个模式中。任何帮助将不胜感激。谢谢!
英文:
I want to create a mat-tree in angular 8 and data should come from the MongoDB database. For this need, I have to make a tree-structured schema in my backend server and then put data in that schema and retrieve it from that schema. Till now I have created mat-tree from local data and made a tree model in my backend server which is as follow:
const mongoose = require('mongoose');
const Schema = mongoose.Schema
const treeSchema = new Schema({
name: String,
parent: {
type: Schema.Types.ObjectId,
ref: 'Node'
},
children: [{
type: Schema.Types.ObjectId,
ref: 'Node'
}],
ancestors: [{
type: Schema.Types.ObjectId,
ref: 'Node'
}]
})
module.exports = mongoose.model('Node', treeSchema)
I don't know how to put and retrieve data from this schema using API service.
any help would be appreciated.
Thanks!
答案1
得分: 2
database mongodb and node js server with express
我找到了使用文档:
https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/mongoose
英文:
database mongodb and node js server with express
i have found to use document
https://developer.mozilla.org/en-US/docs/Learn/Server-side/Express_Nodejs/mongoose
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论