- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在正确查询 MongoDB 时遇到一些问题。我有很多关于每种产品不同时间的价格的文件。更新来自第 3 方服务,每个产品几乎每秒都会实时更新。有时,我在一秒钟内更新 2-3 次价格,或者对于某些产品,每 5-10 秒更新 1 次。
{ "_id": ObjectID("5a4f51ec4f1bdb02f6c82833"), "name": orange", "price": 1.16, "date": ISODate("2018-01-05T09:22:37.983Z"), "unix_date": 1515147756642}
{ "_id": ObjectID("5a4f51eb4f1bdb02f6c82828"), "name": orange", "price": 1.17, "date": ISODate("2018-01-05T09:22:37.530Z"), "unix_date": 1515147755738}
{ "_id": ObjectID("5a4f51ea4f1bdb02f6c8281a"), "name": orange", "price": 1.16, "date": ISODate("2018-01-05T09:22:36.123Z"), "unix_date": 1515147754489}
{ "_id": ObjectID("5a4f51e84f1bdb02f6c82805"), "name": orange", "price": 1.15, "date": ISODate("2018-01-05T09:22:33.937Z"), "unix_date": 1515147752334}
{ "_id": ObjectID("5a4f51e34f1bdb02f6c827d2"), "name": orange", "price": 1.15, "date": ISODate("2018-01-05T09:22:28.890Z"), "unix_date": 1515147747411}
{ "_id": ObjectID("5a4f51ea4f1bdb02f6c82818"), "name": apricot", "price": 2.73, "date": ISODate("2018-01-05T09:22:36.640Z"), "unix_date": 1515147754487}
{ "_id": ObjectID("5a4f51e84f1bdb02f6c82806"), "name": apricot", "price": 2.66, "date": ISODate("2018-01-05T09:22:33.623Z"), "unix_date": 1515147752335}
{ "_id": ObjectID("5a4f51e74f1bdb02f6c827fc"), "name": apricot", "price": 2.59, "date": ISODate("2018-01-05T09:22:33.577Z"), "unix_date": 1515147751196}
{ "_id": ObjectID("5a4f51e34f1bdb02f6c827d7"), "name": apricot", "price": 2.46, "date": ISODate("2018-01-05T09:22:28.967Z"), "unix_date": 1515147747444}
{ "_id": ObjectID("5a4f51dc4f1bdb02f6c8278d"), "name": apricot", "price": 2.51, "date": ISODate("2018-01-05T09:22:22.530Z"), "unix_date": 1515147740183}
{ "_id": ObjectID("5a4f51de4f1bdb02f6c827aa"), "name": melon", "price": 10.1, "date": ISODate("2018-01-05T09:22:22.380Z"), "unix_date": 1515147742511}
{ "_id": ObjectID("5a4f51dd4f1bdb02f6c8279e"), "name": melon", "price": 10.1, "date": ISODate("2018-01-05T09:22:20.830Z"), "unix_date": 1515147741391}
{ "_id": ObjectID("5a4f51dc4f1bdb02f6c82793"), "name": melon", "price": 10.2, "date": ISODate("2018-01-05T09:22:20.113Z"), "unix_date": 1515147740250}
{ "_id": ObjectID("5a4f51db4f1bdb02f6c82782"), "name": melon", "price": 10.1, "date": ISODate("2018-01-05T09:22:18.597Z"), "unix_date": 1515147739137}
{ "_id": ObjectID("5a4f51d64f1bdb02f6c8274c"), "name": melon", "price": 10.0, "date": ISODate("2018-01-05T09:22:12.983Z"), "unix_date": 1515147734131}
{ "_id": ObjectID("5a4f51d34f1bdb02f6c82729"), "name": cherry", "price": 6.21, "date": ISODate("2018-01-05T09:22:12.810Z"), "unix_date": 1515147731148}
{ "_id": ObjectID("5a4f51c94f1bdb02f6c826b5"), "name": cherry", "price": 6.23, "date": ISODate("2018-01-05T09:22:03.733Z"), "unix_date": 1515147721637}
{ "_id": ObjectID("5a4f51c84f1bdb02f6c826a3"), "name": cherry", "price": 6.24, "date": ISODate("2018-01-05T09:22:02.263Z"), "unix_date": 1515147720394}
{ "_id": ObjectID("5a4f51c74f1bdb02f6c82695"), "name": cherry", "price": 6.24, "date": ISODate("2018-01-05T09:22:00.763Z"), "unix_date": 1515147719464}
{ "_id": ObjectID("5a4f51c14f1bdb02f6c82661"), "name": cherry", "price": 6.27, "date": ISODate("2018-01-05T09:21:55.233Z"), "unix_date": 1515147713322}
{ "_id": ObjectID("5a4f51c44f1bdb02f6c8267c"), "name": apple", "price": 1.72, "date": ISODate("2018-01-05T09:21:56.343Z"), "unix_date": 1515147716082}
{ "_id": ObjectID("5a4f51b94f1bdb02f6c8261e"), "name": apple", "price": 1.71, "date": ISODate("2018-01-05T09:21:46.687Z"), "unix_date": 1515147705949}
{ "_id": ObjectID("5a4f51b94f1bdb02f6c8260e"), "name": apple", "price": 1.75, "date": ISODate("2018-01-05T09:21:45.030Z"), "unix_date": 1515147705022}
{ "_id": ObjectID("5a4f51b54f1bdb02f6c825f8"), "name": apple", "price": 1.76, "date": ISODate("2018-01-05T09:21:42.110Z"), "unix_date": 1515147701643}
{ "_id": ObjectID("5a4f51b34f1bdb02f6c825e0"), "name": apple", "price": 1.77, "date": ISODate("2018-01-05T09:21:40.483Z"), "unix_date": 1515147699844}
主要思想是每 5-10 秒向 MongoDB 进行一次查询,以获取实际价格以及此请求之前的价格(10 秒前、30 秒前、100 万年前、500 万年前、1500 万年前)。假设我在 10:00:00 发出请求,我想获取该产品的最后价格、10 秒前的最后价格(09:59:50)、30 秒前的最后价格(09:59:30)等等。
{ "_id" : "orange", "price" : 1.16, "price_10s" : 1.15, "price_30s" : 1.15, "price_1m" : 1.13, "price_5m" : 1.10, "price_15m" : 1.07 }
{ "_id" : "apricot", "price" : 2.73, "price_10s" : 2.51, "price_30s" : 2.48, "price_1m" : 2.40, "price_5m" : 2.41, "price_15m" : 2.35 }
{ "_id" : "melon", "price" : 10.1, "price_10s" : 10.0, "price_30s" : 10.2, "price_1m" : 10.4, "price_5m" : 10.3, "price_15m" : 10.3 }
{ "_id" : "cheryy", "price" : 6.21, "price_10s" : 6.25, "price_30s" : 6.24, "price_1m" : 6.22, "price_5m" : 6.01, "price_15m" : 5.99 }
{ "_id" : "apple", "price" : 1.72, "price_10s" : 1.75, "price_30s" : 1.75, "price_1m" : 1.74, "price_5m" : 1.70, "price_15m" : 1.67 }
通过此查询,我只能获取每种产品的最后价格:
food.aggregate([
{
$group: {
_id: "$name",
price: {$last:"$price"},
date: {$last:"$date"}
}
}
]}
我还可以使用 $match 提出请求,并获取最后的实际价格,即 10 分钟前(或其他时间间隔)。
var today = new Date();
var shift_10m = new Date(today.getTime() - 10*60*1000);
food.aggregate([
{
$match: {
date: { "$lte": shift_10m }
}
}, {
$group: {
_id: "$name",
price: {$last:"$price"},
date: {$last:"$date"}
}
}
]);
但我想在一个查询中获得每种食物的结果以及不同时期的价格。可能吗?
我的MongoDB版本是v3.6.0。我在 Node.js 应用程序中使用 mongoose。
最佳答案
使用$push
food.aggregate([
{
$group: {
_id: "$name",
items: { $push: { price: "$price", date: "$date" } }
}
}
]}
有关 docs 中的 push
的更多信息
关于node.js - MongoDB。通过一次查询获取每种产品不同时间段的价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48164520/
我需要按不同类别过滤我网站上的产品。例如,如果您选择“DRINKS”类别,它将向我显示属于该类别的产品。 为了更好地解释自己。 我需要按类别过滤我网站的出版物 [产品],例如,在选择一个类别时说“饮料
我有 orders 集合,其中包含 products 集合。我将一些产品 ID 作为列表传递给该方法。我需要返回与任何匹配的产品列表input 列表中的 id。 我需要像这样使用 foreach 循环
我已经为临时分发进行存档好几个月了,但今天突然我无法这样做,因为“存档”菜单项已被禁用。我没有改变任何东西。我完成了该项目的配置设置,看起来没问题。 我的临时个人资料即将在 14 天后过期。这可能是问
我正在尝试找出产品和产品属性之间的关系。我有一个 product 表和一个 product_attributes 表。产品可以具有多种属性。我需要查询来查找具有一个特定属性和另一个属性之一的所有产品。
我正在使用 MySQL Workbench 创建 EER 图。 实现产品、类别和公司表之间关系的最佳方式是什么? 我正在考虑这种关系,但考虑到我想让公司的客户管理自己的产品/类别,这是最好的方式吗?如
我正在使用 itertools 包,并尝试在具有 900 个值的数组中创建 1、2 和 3 的所有可能组合,然后将其转换为 30 x 30 矩阵。我必须执行此操作的代码在下面并且工作正常。 for d
我有几个关于 Cartridge 启动器的问题: 我的产品不需要评级或发布日期。他们永远不会出售。一些产品是可下载的,因此“num_in_stock”不相关或本质上是无限制的。没有颜色选项,只有尺寸。
在 MySQL 中,存储产品价格(或一般货币)的首选列类型是什么?谷歌知道我经常使用 DECIMAL of FLOAT,但我想知道哪个更好。 我存储的价格范围是 0.01 到 25.00。当然更高的值
在软件开发过程中,尤其是在准备将新功能或修复后的版本上线之前,进行详尽的自测和上线前检查是至关重要的。以下是一个从多个维度综合考量的上线升级检查清单(Checklist),旨在帮助团队确保软件质量、稳
我正在创建一个闪购网站,并且我已经在主页和商店页面上根据日期范围显示产品。但我也想根据其他地方的日期范围显示产品,因此使用简码。 这是我的代码: function testt($meta_query)
可以在 WooCommerce 上批量创建产品吗?我正在使用 wp-cli Product 命令,但似乎我必须一个一个地创建。 'My product 1'), array('title'
我有一个带有数量和价格列的 excel 文件,我用它来为插件 WooCommerce Dynamic Pricing 创建必要的输出的定价规则。 我几乎想通了,但是 WooCommerce 进口商正在
我刚刚继承了一个woocommerce项目,我需要将主页更改为仅显示特定品牌。他们设置了 Product-Data => Attribute => pa_brand。 如果我打印 pa_brand 数
在插件中如何使用 wc_get_products() 获取产品。或者有其他方法可以做到吗? if ( in_array( 'woocommerce/woocommerce.php', apply_fi
我正在做一个无法从公司网络外部访问的内部网,他们希望在 Plone 中显示一些关于文件下载和最常查看的页面的不错的统计数据。 由于网络限制,我无法使用谷歌分析或任何类型的外部服务,那么是否有任何产品可
我正在就以下问题寻求建议: 保留哪些产品 key 属于哪个客户端的列表。例如,如果我的产品 key 为 8456-7894-4567-7894,则应该这样设计,以便将列表写入数据库而不是文件。 如何将
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
尝试将产品搜索栏添加到 Wordpress 管理栏后端,以进行 Woocommerce 产品搜索。它将位于后端管理菜单栏的顶部,这样无论您在后端的哪个位置,都可以搜索 woo 的产品。我很接近但在小绊
这让我抓狂.. 我正在尝试根据特定属性查询和输出 WooCommerce 产品。例如,我设置了一个名为 on 的属性,可能的值为 yes或 no . 我使用以下查询: $args = array(
我正在尝试从 Shopify 商店获取所有产品的 JSON。我一直在向 {STORE URL}/products.json 端点。但这最终只显示了商店提供的部分产品(很多,但不是全部)。当我将参数更改
我是一名优秀的程序员,十分优秀!