CentOS 7 Shell 操作 MongoDB

准备测试库
[dev@hessian01 ~]$ mongo --quiet 192.168.8.147:21234/zhanghq_test --authenticationDatabase zhanghq_test -u zhanghq -p 123456 --eval "db.inventory.find({ })"

{ "_id" : ObjectId("61a82c8cfc568e1535e2c22a"), "item" : "journal", "qty" : 25, "size" : { "h" : 14, "w" : 21, "uom" : "cm" }, "status" : "A" }
{ "_id" : ObjectId("61a82c8cfc568e1535e2c22b"), "item" : "notebook", "qty" : 50, "size" : { "h" : 8.5, "w" : 11, "uom" : "in" }, "status" : "P" }
{ "_id" : ObjectId("61a82c8cfc568e1535e2c22c"), "item" : "paper", "qty" : 100, "size" : { "h" : 8.5, "w" : 11, "uom" : "in" }, "status" : "D" }
{ "_id" : ObjectId("61a82c8cfc568e1535e2c22d"), "item" : "planner", "qty" : 75, "size" : { "h" : 22.85, "w" : 30, "uom" : "cm" }, "status" : "D" }
{ "_id" : ObjectId("61a82c8cfc568e1535e2c22e"), "item" : "postcard", "qty" : 45, "size" : { "h" : 10, "w" : 15.25, "uom" : "cm" }, "status" : "A" }
查看特定条件内容
[dev@hessian01 ~]$ mongo --quiet 192.168.8.147:21234/zhanghq_test --authenticationDatabase zhanghq_test -u zhanghq -p 123456 --eval "db.inventory.find({ status:'A' })"
{ "_id" : ObjectId("61a82c8cfc568e1535e2c22a"), "item" : "journal", "qty" : 25, "size" : { "h" : 14, "w" : 21, "uom" : "cm" }, "status" : "A" }
{ "_id" : ObjectId("61a82c8cfc568e1535e2c22e"), "item" : "postcard", "qty" : 45, "size" : { "h" : 10, "w" : 15.25, "uom" : "cm" }, "status" : "A" }
删除特定内容数据
[dev@hessian01 ~]$ mongo --quiet 192.168.8.147:21234/zhanghq_test --authenticationDatabase zhanghq_test -u zhanghq -p 123456 --eval "db.inventory.deleteMany({ status:'A' })"
{ "acknowledged" : true, "deletedCount" : 2 }
验证结果
[dev@hessian01 ~]$ mongo --quiet 192.168.8.147:21234/zhanghq_test --authenticationDatabase zhanghq_test -u zhanghq -p 123456 --eval "db.inventory.find({ })"
{ "_id" : ObjectId("61a82c8cfc568e1535e2c22b"), "item" : "notebook", "qty" : 50, "size" : { "h" : 8.5, "w" : 11, "uom" : "in" }, "status" : "P" }
{ "_id" : ObjectId("61a82c8cfc568e1535e2c22c"), "item" : "paper", "qty" : 100, "size" : { "h" : 8.5, "w" : 11, "uom" : "in" }, "status" : "D" }
{ "_id" : ObjectId("61a82c8cfc568e1535e2c22d"), "item" : "planner", "qty" : 75, "size" : { "h" : 22.85, "w" : 30, "uom" : "cm" }, "status" : "D" }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值