批处理之家's Archiver

2565549687 发表于 2022-5-7 18:11

请教一个关于linux shell和mongodb数据库交互的问题?

[code] { "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" }[/code]以上是数据库peg里的表集合movies的内容。接下来请看我写的shell脚本[code]#!/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 [/code]请问我应该如何做才能把在mongodb中查询的值传到linux shell 中的变量来使用呢?

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.