Node JS:填充自动增量字段(猫鼬)
Node JS : Populate auto increment field (Mongoose)
我有两个集合,第一个是自动递增字段,
我在第二个集合中引用了自动递增字段,但是使用填充函数的查找没有return填充的结果。
表 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);
表2
const table2Schema = mongoose.Schema({
categoryId: { type: Number, ref: "table1" },
displayed: { type: Boolean, default: true }
});
module.exports = mongoose.model("table2", table2Schema);
查询:
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”字段编号,
我删除了自动增量的声明并且它成功运行
我有两个集合,第一个是自动递增字段,
我在第二个集合中引用了自动递增字段,但是使用填充函数的查找没有return填充的结果。
表 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);
表2
const table2Schema = mongoose.Schema({
categoryId: { type: Number, ref: "table1" },
displayed: { type: Boolean, default: true }
});
module.exports = mongoose.model("table2", table2Schema);
查询:
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”字段编号, 我删除了自动增量的声明并且它成功运行