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
MongoDB根据数组长度查询
查出数组长度等于3的记录
db.user.find({ books: { $size: 3} })
Ubuntu 设置MongoDB自动启动
Ubuntu 18.04+
sudo systemctl enable mongod.service
https://askubuntu.com/questions/61503/how-to-start-mongodb-server-on-system-start
在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
MongoDB备份与还原
今天迁移MongoDB数据库出现了很奇怪的问题,使用的方法如下:
备份方法:
mongodump -h dbhost -d dbname -o dbdirectory
还原方法:
mongorestore -h <hostname><:port> -d dbname <path>