- { "item": "journal", "qty": 25, "size": { "h": 14, "w": 21, "uom": "cm" }, "status": "A" },
- { "item": "notebook", "qty": 50, "size": { "h": 8.5, "w": 11, "uom": "in" }, "status": "A" },
- { "item": "paper", "qty": 100, "size": { "h": 8.5, "w": 11, "uom": "in" }, "status": "D" },
- { "item": "planner", "qty": 75, "size": { "h": 22.85, "w": 30, "uom": "cm" }, "status": "D" },
- { "item": "postcard", "qty": 45, "size": { "h": 10, "w": 15.25, "uom": "cm" }, "status": "A" }
复制代码 以上是数据库peg里的表集合movies的内容。接下来请看我写的shell脚本- #!/bin/bash
- pp='666'
- /usr/local/mongodb/bin/mongo 127.0.0.1:27017/peg <<EOF
-
- var arr=db.movies.find().pretty()
- pp=arr.toArray()[0]["size"][0]["h"]
- #这里是备注内容请忽略:此时pp的内容为 14
- EOF
- echo $pp
- #这里是备注内容请忽略:我希望这里的pp输出结果为14 但是事实上结果还是最初的赋值 666
复制代码 请问我应该如何做才能把在mongodb中查询的值传到linux shell 中的变量来使用呢? |