mongodb 连表查询

1
2
3
4
5
6
7
8
9
10
11
db.publisher.aggregate([
{
$lookup:
{
from: "docs",
localField: "name",
foreignField: "publisher",
as: "inventory_docs"
}
},
])

修改mongodb 4.2 默认事务锁最大等待时间

1
2
3
4
5
db.adminCommand( { setParameter: 1, maxTransactionLockRequestTimeoutMillis: 3000 } )

or

mongod --setParameter maxTransactionLockRequestTimeoutMillis=3000

apt一键部署mongo脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 执行操作前, 需要操作/etc/resolv.conf文件
# 在文件中增加以下两行内容
# nameserver 202.96.134.133
# nameserver 8.8.8.8

#!/bin/bash
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 68818C72E52529D4

sudo echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

sudo apt-get update
sudo apt-get purge mongodb mongodb-server mongodb-server-core mongodb-clients

cd /
mkdir data
cd data
mkdir db
mkdir log

mongod --dbpath /data/db --fork --logpath /data/log/mongodb.log

read -p "Enter your account:" account
read -p "Enter your password:" password
mongo --eval "use admin;db.createUser({user:'$account',pwd:'$password',roles: [ { role: "root", db: "admin" } ] });"

ID=`ps -ef | grep "mongod" | grep -v "grep" | awk '{print $2}'`
for id in $ID
do
kill -9 $id
done

mongod -auth --dbpath /data/db --fork --logpath /data/log/mongodb.log --port 28000 --bind_ip_all --wiredTigerCacheSizeGB 1