小虾虎鱼

小虾虎鱼

Mongoose使用populate时不使用默认的_id字段

 2020/08/05 12:14 阅读全文 »

Ubuntu中手动安装MongoDB后添加服务

官方手动安装方法

创建配置文件

执行命令: sudo vim /etc/mongodb/mongod.conf 并添加以下内容

systemLog:
  destination: file
  path: /var/log/mongodb/mongod.log
  logAppend: true
storage:
  dbPath: /var/lib/mongo
net:
  bindIp: 127.0.0.1
 2020/07/11 15:49 阅读全文 »

MongoDB根据数组长度查询

查出数组长度等于3的记录

db.user.find({ books: { $size: 3} })
 2019/10/11 00:31 阅读全文 »

Ubuntu 设置MongoDB自动启动

 2019/08/20 20:16 阅读全文 »

在MacOS X中如何让MongoDB在开机时自动启动

So, everytime when I have to start my node apps I often forgot to run my MongoDB service and it is a bit annoying where you have to have one tab dedicated to something you won't touch at all and I thought I should find a way to run this from my startup item on my Mac OS X.

Luckily, this post from Hunter Ford's blog explains how to run your MongoDB in your Startup item on Mac OS X and here is how:

Create a file call org.mongo.mongod.plist in /Library/LaunchDaemons/

If you use vim you can do like this:

sudo vim /Library/LaunchDaemons/org.mongo.mongod.plist
 2017/10/01 16:42 阅读全文 »

MongoDB备份与还原

今天迁移MongoDB数据库出现了很奇怪的问题,使用的方法如下:

备份方法:
mongodump -h dbhost -d dbname -o dbdirectory
还原方法:
mongorestore -h <hostname><:port> -d dbname <path>
 2017/09/02 18:34 阅读全文 »