简体   繁体   English

深流1-n关系

[英]Deepstream 1 - n relation

I'm trying to build a user notification using Deepstream.io . 我正在尝试使用Deepstream.io构建user notification I'm using deepstream.io-storage-mongodb for storage. 我正在使用deepstream.io-storage-mongodb进行存储。 My data structure: 我的数据结构:

User
=================
id - email - others


Notication
=================
userId - notification

I'm try to implement 1-n modelling deepsteam tutorial . 我正在尝试实现1-n建模deepsteam教程 But I can't understand how can I do this. 但是我不明白该怎么办。 How can I store pointer or how can I point towards a List ? 如何存储指针或如何指向List Or how can I implement notification using deepstream ? 或者如何使用deepstream实施通知?

Thanks in Advance. 提前致谢。

you can try as like as given below (I'm using JS ): 您可以尝试如下所示(我使用JS ):

Receive Notication 收到通知

var client = deepstream( 'localhost:6020' );
client.login();

// Unique Identification for user
let uniqueId = `userId:${userId}`;

// Mongodb collection : Notification 
statusRecord = client.record.getList("Notification/" + uniqueId);

statusRecord.subscribe(function(data) {
    data.forEach(function(name) {
        var record = client.record.getRecord(name);
        record.whenReady(function(r) {
           // all notification
           console.log( "r ==> ", r.get() );
        });
    });
});

Send Notification 发送通知

const ds = deepstream( 'localhost:6020' );

ds.login();

// userId
const list = this.ds.record.getList( `Notification/${userId}` );

// id for notification
let id = `Notification/${this.ds.getUid()}`;

let record = this.ds.record.getRecord(id);
record.set( {
  message: 'information'// save notification data
});

list.addEntry(id);

Hope it will solve your problem. 希望它能解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM