0

我正在尝试在 mongo 的 Grid fs 中向文件对象添加一个元数据。但它没有在 Gridfs 中更新(实际上我正在添加名为 page 的新属性)元数据。

以下是我的代码,在保存文档后,它会尝试使用其他属性更新该文件。

fs.createReadStream(file)
          .pipe(bucket.openUploadStream(documentId.toString()))
          .on('finish', async (savedFile: File) => {
            let page = 1;

            const letssee = await FilesModel(
              projectContext,
              bucketName,
            ).findById(savedFile._id); // findById is working.

            await FilesModel(
              projectContext,
              bucketName,
            ).findByIdAndUpdate(savedFile._id, { $set: { page } }); // findByIdAndUpdate is not working.

          });

我在这里做错了什么?或者只是 Grid Fs 对象不支持元数据更新?

4

1 回答 1

0

从评论中,解决方案是:

尝试.exec()findByIdAndUpdate查询后添加

像这样使用await Model.find().exec()

于 2021-07-06T16:30:32.677 回答