![](/img/trans.png)
[英]What is the NodeJS mongoDB client equivalent to Mongoose populate?
[英]Need help in NodeJs and MongoDB problem (Mongoose populate is not working)
这是我的模式
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const finalDocument = new Schema({
name: {
type: String,
},
Properties: {
type: mongoose.Schema.Types.ObjectId,
ref: "Properties",
},
borrower: {
type: mongoose.Schema.Types.ObjectId,
ref: "borrowers",
},
});
var FinalDocuments = mongoose.model("finalDocument", finalDocument);
module.exports = FinalDocuments;
这是我的路线。
finalDocument
.find({})
.populate("borrower")
.exec()
.then((brws) => {
res.statusCode = 200;
res.setHeader("Content-Type", "application/json");
res.json(brws);
})
.catch((err) => {
console.log("error in getting borrowers", err);
});
当我打电话给这条路线时,没有人填写借款人。 我附上Postman的照片。
您的代码似乎没有问题。
可能的原因是:
borrower: { type: mongoose.Schema.Types.ObjectId, ref: "borrowers", }
中提到的集合名称在您的架构中可能是拼写错误或定义了错误的架构名称
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.