我正在尝试使用user notification
构建Deepstream.io
。我正在使用deepstream.io-storage-mongodb
进行存储。我的数据结构:
User
=================
id - email - others
Notication
=================
userId - notification
我正在尝试实现1-n modelling deepsteam tutorial。但是我不明白该怎么办。如何存储指针或如何指向List
?或者如何使用deepstream
实施通知?
谢谢。
答案 0 :(得分: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);
希望它能解决您的问题。