Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Mongoose查找和更新子文档_Node.js_Mongoose - Fatal编程技术网

Node.js Mongoose查找和更新子文档

Node.js Mongoose查找和更新子文档,node.js,mongoose,Node.js,Mongoose,我有以下模式: const FinanceSchema = new mongoose.Schema({ moneyToBePaid: { type: Number, }, moneyPaid: { type: Number, }, moneyToBeReceived: { type: Number, }, moneyReceived: { type: Number, }, }); const UserSchema = new

我有以下模式:

const FinanceSchema = new mongoose.Schema({
  moneyToBePaid: {
    type: Number,
  },

  moneyPaid: {
    type: Number,
  },

  moneyToBeReceived: {
    type: Number,
  },

  moneyReceived: {
    type: Number,
  },
});

const UserSchema = new mongoose.Schema({
  firstname: {
    type: String,
    required: true,
  },
  lastname: {
    type: String,
    required: true,
  },
  email: {
    type: String,
    required: true,
    unique: true,
  },
  password: {
    type: String,
    required: true,
  },
  phoneNo: {
    type: Number,
    required: true,
  },
  financialInformation: [FinanceSchema],
});
因此,对于每个用户,我都可以获得尽可能多的财务信息。 我可以在用户集合中保存财务信息,但无法更新财务信息记录

假设我有两个财务信息记录:

"firstname":"John",
...................................... ,
"financialInformation":[{
"_id": "5f9116c70785f818e8404f9ff",
moneyToBePaid: 200,

  moneyPaid:300,

  moneyToBeReceived:400,

  moneyReceived:500
},{
"_id": "5f9116c70785f818e8404f9e"
moneyToBePaid: 100,

  moneyPaid:100,

  moneyToBeReceived:100,

  moneyReceived:100
}]
现在我想更新第一个financialInfo

router.patch("/users/:user_id/profile/:finance_id", async (req, res) => {
  const finance_id = req.params.finance_id;
  const user_id = req.params.user_id;

  try {

   }