Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
854 views
in Technique[技术] by (71.8m points)

node.js - MongooseError: Operation `orders.deleteMany()` buffering timed out after 10000ms

when I run my app with npm run seeder
then I have face this error I have checked my database connection carefully, it's ok. also, I have checked my ordermodels file it's also ok. I have used MongoDB compass there is nothing problem. I don't know why showing buffering timed out.

MongooseError: Operation `orders.deleteMany()` buffering timed out after 10000ms

seeder.js

    import mongoose from "mongoose";
    import dotenv from "dotenv";
    import colors from "colors";
    import users from "./data/users.js";
    import products from "./data/products.js";
    import User from "./models/userModel.js";
    import Product from "./models/productModel.js";
    import Order from "./models/orderModel.js";
    import connectDB from "./config/db.js";
    
    dotenv.config();
    connectDB();
    
    const importData = async () => {
      try {
        await Order.deleteMany();
        await Product.deleteMany();
        await User.deleteMany();
    
        const createUsers = await User.insertMany(users);
        const adminUser = createUsers[0]._id;
        const sampleProducts = products.map((product) => {
          return { ...product, user: adminUser };
        });
        await Product.insertMany(sampleProducts);
    
        console.log("Data Imported".green.inverse);
        process.exit();
      } catch (error) {
        console.error(`${error}`.red.inverse);
        process.exit(1);
      }
    };
    
    const DeleteData = async () => {
      try {
        await Order.deleteMany();
        await Product.deleteMany();
        await User.deleteMany();
    
        console.log("Data Deleted".red.inverse);
        process.exit();
      } catch (error) {
        console.error(`${error}`.red.inverse);
        process.exit(1);
      }
    };
    
    if (process.argv[2] === "-d") {
      DeleteData();
    } else {
      importData();
    }
question from:https://stackoverflow.com/questions/65599791/mongooseerror-operation-orders-deletemany-buffering-timed-out-after-10000ms

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

use following code for connect to mongodb

const mongoose = require('mongoose')
mongoose.connect(url, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true })

after that you should removing the node_module folder and all .json files and reinstalling the mongoose and use npm update


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...