#删除表 [root@localhost ~]# mongo localhost:23000/testdb-2 --eval "db.table1.drop();" MongoDB shell version v3.6.13 connecting to: mongodb://localhost:23000/testdb-2?gssapiServiceName=mongodb Implicit session: session { "id" : UUID("0cf5b11f-c6ef-417c-8bbd-a2f8414f589c") } MongoDB server version: 3.6.13 true
10 shell脚本中使用mongo命令
#!/bin/bash mongo localhost:23000/testdb-2 <<EOF var cursor=db.table2.find(); while (cursor.hasNext()){ var item = cursor.next(); print(item.name);
} EOF
#传参的方式 #!/bin/bash table_name=$1 mongo localhost:23000/testdb-2 <<EOF var cursor=db.${table_name}.find(); while (cursor.hasNext()){ var item = cursor.next(); print(item.name);