我有这个架构的通知集合
import numpy as np
import matplotlib.pyplot as plt
A = np.matrix([[10,1],[45,1]])
B = np.matrix([[180],[140]])
A_inverse = np.linalg.inv(A)
X = A_inverse * B
T = np.arange(10) + (np.random.rand(10)-0.5) # some "random" T
line = np.vstack((T, np.ones(T.shape))).transpose().dot(X)
plt.plot(T, line, 'r*')
如何将像facebook这样的通知分组,“其他50人喜欢你的帖子”?
如何为具有相同_parent的文档检索此形状的数据?
_const notificationsSchema = new Schema({
_from: {
type: Schema.ObjectId, ref: 'User',
},
_to: {
type: Schema.ObjectId, ref: 'User',
},
_target: String,
type: {
type: String,
},
createdAt: {
type: Date,
default: Date.now,
},
});
答案 0 :(得分:0)
这是一个非常开放的回应。没有一个正确的答案。我为这个问题提供了一个天真和理想的方法。你可能会想到另一个更好的方法。
你需要有一个“喜欢”集合的东西,你可以存储来自用户的所有喜欢,其中每个喜欢都有对喜欢的帖子的引用。然后你必须对likes集合执行聚合,以获得所有喜欢的帖子,其中postId等于你想要的帖子的id。
首次尝试。
然后一个更好的“现实世界”方法是在Post文档中添加一个“likesCount”(称之为你想要的)属性,以便在帖子上保留喜欢的内容。每次用户喜欢/不喜欢该帖子时更新likesCount。这样,每次必须显示数据时,您实际上不必一遍又一遍地搜索“喜欢”集合。