小编Sha*_*iri的帖子

类型参数 '{ useNewUrlParser: boolean; useUnifiedTopology: boolean}' 不可分配给类型' 的参数

我正在尝试将 Node.js 服务器连接到 Atlas mongo 数据库。我为此使用猫鼬。

\n
await mongoose\n      .connect(process.env.MONGO_URI!, {\n        useNewUrlParser: true,\n        useUnifiedTopology: true,\n        useCreateIndex: true,\n        useFindAndModify: false,\n        poolSize: parseInt(process.env.POOL_SIZE!),\n      })\n      .then((res) => {\n        console.log(\n          'Connected to Distribution API Database - Initial Connection'\n        );\n      })\n      .catch((err) => {\n        console.log(\n          `Initial Distribution API Database connection error occured -`,\n          err\n        );\n      });\n
Run Code Online (Sandbox Code Playgroud)\n

我在 package.json 文件中与此相关的依赖项如下

\n
"dependencies": {\n    "@types/mongoose": "5.7.29",\n    "mongoose": "5.9.21",\n    "typescript": "3.9.5"\n  },\n
Run Code Online (Sandbox Code Playgroud)\n

这是早些时候工作的,没有任何问题(我根本没有更新 @types/mongoose 或 mongoose 版本),现在突然出现以下错误

\n
Compilation error in /app/src/index.ts\nUsing ts-node version 8.10.2, typescript …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb typescript

15
推荐指数
4
解决办法
2万
查看次数

事务 1 已在 MongoDB 中提交

我正在尝试使用事务来更新多个文档。

一种是加载表单文档 [await Sheet.save({ session });]

另一个是库存预订记录数组 [await Stock.bulkWrite()]。

    const session = await mongoose.startSession();

    session.startTransaction({
      readPreference: 'primary',
      readConcern: { level: 'local' },
      writeConcern: { w: 'majority' },
    });

    let sheetAfterSave: any = null;

    try {
      sheetAfterSave = await sheet.save({ session });
      records.forEach(async (el: any) => {
        let updatedStockRecord = await Stock.bulkWrite(
          [
            {
              updateOne: {
                filter: {
                  index: el.index,
                  product: el.product,
                  batchNo: el.batchNo,
                  agency,
                  totalQuantity: { $gte: el.loadingTotal },
                },
                update: {
                  $push: {
                    reservations: {
                      loadingSheetId: sheetAfterSave._id,
                      reservedCaseQuantity: el.loadingCaseCount, …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb

3
推荐指数
1
解决办法
5653
查看次数

标签 统计

mongodb ×2

mongoose ×2

typescript ×1