有时候需要把从一个集合里查询的结果保存为一个集合,可以用以下写法:<wbr style=""><div style="">
<div style="line-height:25px">var temp1 = db.mtb1.find(name:"joe");</div>
<div style="line-height:25px">while(temp1.hasNext()) db.tab2.insert(temp1.next());</div>
</div>
<div style="">相当于sql中:create table tab2 as select * from mtb1 where name='joe';</div>
<div style=""><br style="line-height:25px"></div>
<div style=""><br style="line-height:25px"></div>
<div style="">另外mongoexport提供条件过滤功能:</div>
<div style="">mtb1表里有一个字段为name,值有joe,可以根据条件导出所需数据:</div>
<div style="">mongoexport -h 127.0.0.1 --port 50000 -d testdb -c mtb1 -q '{name:"joe"}' -o mtb1.dmp</div>
<div style="">导出name为joe的数据</div>
</wbr>
mongodb 查询结果保存为结果集以及根据条件导出数据
最新推荐文章于 2024-07-10 20:11:28 发布