如何通过在mongodb中的另一个集合中发送名称之类的数据之一来保存集合的特定数据的ID

//bills collections
const mongoose = require('mongoose');  
const Schema = mongoose.Schema;  
// Define collection and schema for Product  
let bills = new Schema({  
  Id: { type: String },Name: { type: String },money: { type: Number },Perc: { type: String },Month: { type: String },branchName:{type: mongoose.Schema.Types.ObjectId,ref: 'branches'},},{  
    collection: 'bills'  
});  
module.exports = mongoose.model('bills',bills); 

//branches collection
const mongoose = require('mongoose');  
const Schema = mongoose.Schema;  
// Define collection and schema for Product  
let branches = new Schema({  
  branchName: {  
    type: String  
  },{  
    collection: 'branches'  
});  
module.exports = mongoose.model('branches',branches); 

如果我将Secunderabad作为branchName的branchName发送给账单集,则与分支集合_id中的Secunderabad相比,它保存了另一个ID 双子城是分支机构之一 然后我要成为相同的ID。

yangliuliu2009 回答:如何通过在mongodb中的另一个集合中发送名称之类的数据之一来保存集合的特定数据的ID

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3126411.html

大家都在问