【发布时间】:2018-09-08 07:27:39
【问题描述】:
我已将以下 JSON 文件上传到 mongoDB 数据库: https://cloudpricingcalculator.appspot.com/static/data/pricelist.json
我已成功使用 app.js 中的以下行访问它:
db.googlepricelist.find({},
{"gcp_price_list":1}).pipe(JSONStream.stringify()).pipe(res);
我想查询对象gcp_price_list 中的所有对象,其中对象的名称包含子字符串“VMIMAGE”。
例如下面的对象:
"CP-COMPUTEENGINE-VMIMAGE-F1-MICRO"
"CP-COMPUTEENGINE-VMIMAGE-G1-SMALL"
我不知道如何定义能够执行此操作的查询。
到目前为止,我尝试过这个:
db.googlepricelist.find({$where: function() {
for (var key in this.gcp_price_list) {
if (key.indexOf("VMIMAGE")!=-1) {
return true;
}
return false;
}
},}).pipe(JSONStream.stringify()).pipe(res);
【问题讨论】:
-
从那里我认为
db.googlepricelist.find({$where: function() { for (var key in this) { if (key.indexOf("VMIMAGE")!=-1) { return true; } return false; } },}).pipe(JSONStream.stringify()).pipe(res);可能有效,但不幸的是它没有。
标签: javascript mongodb