如何在Parse SDK中运行复杂的查询

问题描述 投票:1回答:1

我在Parse DB中有一个设备表,其中列出了用户的设备。每行都有一个指向_User类的指针。该文档还包含last_accessed日期。

设备集合

+----------+-------------+--------------------------+----------------------+
| objectId | device_type | last_accessed            | user Pointer <_User> |
+----------+-------------+--------------------------+----------------------+
| dfsQs0X  | iPhone      | 2020-05-21T18:30:22.761Z | eFjbWQdC1a           |
+----------+-------------+--------------------------+----------------------+

用户收藏

+------------+-------------------+------------+
| objectId   | email             | isVerified |
+------------+-------------------+------------+
| eFjbWQdC1a | [email protected] | true       |
+------------+-------------------+------------+

Note:用户可以具有多个设备。

我正在寻找一种解决方案,以解决最近7天内访问过其设备(用于分析目的)的所有已验证帐户(isVerified = true)的总数。 我尝试过的

async function getActiveAccounts() { // Active Accounts are those who logged in to the App within the last 7 days const today = new Date(); const startDate = new Date(today); startDate.setDate(startDate.getDate() - 7); const query = new Parse.Query("Device").greaterThan("last_accessed", startDate); return query.count(); } 但是,此代码返回设备的数量,但不会被唯一的经过验证的用户过滤。如何更改查询以输出最近7天内至少登录过一台设备的唯一身份验证用户的数量

我在Parse DB中有一个设备表,其中列出了用户的设备。每行都有一个指向_User类的指针。该文档还包含last_accessed日期。设备集合+ ---------- + ------...
javascript node.js mongodb parse-platform
1个回答
1
投票
async function getActiveAccounts() { // Active Accounts are those who logged in to the App within the last 7 days const today = new Date(); const startDate = new Date(today); startDate.setDate(startDate.getDate() - 7); const query = new Parse.Query("Device").greaterThan("last_accessed", startDate); query.select("objectId")//count isn't available on distinct queries, so just select the objectId as the only data to retrieve query.limit(10000)//make this is high as is reasonable var devices = await query.distinct("user"); return devices.length; }
© www.soinside.com 2019 - 2024. All rights reserved.