[英]Node JS : Populate auto increment field (Mongoose)
I have two collections, the first is with an auto increment field,我有两个集合,第一个是自动增量字段,
I make a reference in the second collection to the auto increment field, but the find with populate function doesn't return the populated result.我在第二个集合中引用了自动增量字段,但是使用 populate 函数的 find 不会返回填充的结果。
Table1表格1
const mongoose = require("mongoose");
var autoIncrement = require("mongoose-auto-increment");
const table1Schema = mongoose.Schema({
name: String,
displayed: { type: Boolean, default: true },
updatedAt: Date,
createdAt: Date
});
autoIncrement.initialize(mongoose.connection);
table1Schema.plugin(autoIncrement.plugin, { model: "table1", startAt: 1 });
module.exports = mongoose.model("table1", table1Schema);
table2表2
const table2Schema = mongoose.Schema({
categoryId: { type: Number, ref: "table1" },
displayed: { type: Boolean, default: true }
});
module.exports = mongoose.model("table2", table2Schema);
Query:询问:
var table2_schema = require("../schemas/table2_schema.js");
module.exports.findPopulateFunction = function() {
table2_schema
.find({})
.populate("categoryId")
.exec(function(err, doc) {
console.log("err : ", err);
console.log("docxx : ", doc);
});
};
问题是我正在使用脚本插入“_id”字段编号,我删除了自动增量的声明并且它成功运行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.