0

我正在尝试构建一个user notificationusing Deepstream.io. 我是deepstream.io-storage-mongodb用来存储的。我的数据结构:

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


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

我正在尝试实现1-n 建模 deepsteam 教程。但我不明白我该怎么做。如何存储指针或如何指向一个List?或者我如何使用 实现通知deepstream

提前致谢。

4

1 回答 1

1

您可以尝试如下所示(我正在使用JS):

接收通知

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() );
        });
    });
});

发送通知

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);

希望它能解决你的问题。

于 2018-10-04T08:48:42.443 回答