工具: mongodb、mongoose

MongoDB云数据库Atlas使用

云远程

  1. const MongoClient = require('mongodb').MongoClient;
  2. const uri = "mongodb+srv://zhaocchen:<password>@cluster0.tjac2.mongodb.net/myFirstDatabase?retryWrites=true&w=majority";
  3. const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });
  4. client.connect(err => {
  5. const collection = client.db("test").collection("devices");
  6. // perform actions on the collection object
  7. client.close();
  8. });

安装

  1. netstat -lanp | grep "27017"
  2. whereis mongodb

安装错误

  1. // error
  2. ./mongod: error while loading shared libraries: libcrypto.so.1.0.0: cannot open shared object file: No such file or directory
  3. // 查看需要哪些依赖
  4. ldd /usr/local/mongodb4/bin/mongod
  5. libcrypto.so.1.0.0 => not found
  6. libssl.so.1.0.0 => not found
  7. libc.so.6 => /lib64/libc.so.6 (0x00007fc1fec04000)
  8. // 设置软连接
  9. ln -s /usr/lib/libcrypto.so.1.0.0 /lib64/libcrypto.so.1.0.0
  10. ln -s /usr/lib/libssl.so.1.0.0 /lib64/libssl.so.1.0.0
  11. // 删除软连接
  12. rm -rf /lib64/libssl.so.1.0.0
  13. yum whatprovides libcrypto.so.1.0.0

https://www.jianshu.com/p/d403f5bbc58e