代码之家  ›  专栏  ›  技术社区  ›  hardikdevios

NodeJS和MongoDB的模式结构建议

  •  0
  • hardikdevios  · 技术社区  · 7 年前

    我有一些问题 Node.js 和 MongoDB API

    像 MongoDB公司 是 NoSQL 我们不能像SQL一样使用关系查询,所以我必须从所有业务中获取业务,然后找到该业务的用户,然后检查用户角色(根据逻辑),然后我可以找到设备信息,在那里我得到了设备令牌,用于发送移动和web推送通知,其中 device_type 无论是网络还是移动。

    这样我就可以发送推送通知,现在当我从客户机获取额外信息时,问题就出现了,比如我们需要将通知存储在模式中,所以在发送推送通知后,我必须将通知存储到一个模式中。在更新代码以存储该通知时,有些通知已存储,有些未存储,我需要知道我的情况(代码结构或数据结构)有什么问题。

    我知道我必须管理数据结构,就像 RDBMS 。如果我的数据结构有误,请根据 MongoDB公司 结构,如果结构没有问题,请指导我使用代码结构。?

    1 回复  |  直到 7 年前
        1
  •  0
  •   Sandeep    7 年前

    问题出在代码中

    let count = 0;
    tokens.forEach(function (to) {
        let message = {
            to: to,
            notification: {
                title: varConst.APP_NAME,
                body: notification
            },
            data: payload
        };
    
        fcmWeb.send(message, function (err, response) {
            if (err) {
                console.log("Something has gone wrong!");
            } else {
                console.log("Successfully sent with response: ", response);
            }
    
            count++;
            if (count == tokens.length) {
                callback("Send All");
            }
        });
    });
    

    在上面的代码块中,不用使用forEach,只需给出注册id的数组,fcm将处理其余的部分。

    let message = {
        registration_ids:["eJ8-S5jddyI:APA91bG1jmJBVEtB04","eJ8-S5jddyI:APA91bG1jmJBVEtB04"],
        notification: {
            title: varConst.APP_NAME,
            body: notification
        },
        data: payload
    };