mongodb

mongodb安装配置完成后 开启服务器命令  

  mongod  --dbpath c:datadb     (c盘)

//创建客户端模块

const mongoClient = require("mongodb").MongoClient  

//定义数据库地址

const  dburl = “mongodb://127.0.0.1:27017”;

//定义连接的数据库

const dbname = “ddpro”;

//定义链接的表

const dbcollection = “pro”;

mongoClient.connect(dburl,(err,client)=>{

  //错误抛出异常

  if(err) throw new Error(err);

  //链接数据库和数据库中的表

  const  collection  = client.db(dbname).collection(dbcollertion);

  //增删改查  

  collection.save({usernmae:"DD",password:"dd"},(err,result)=>{

    if(err) throw new Error("添加失败“);

    client.close();

  })

})

原文地址:https://www.cnblogs.com/dd86/p/11196170.html