小编Api*_*hai的帖子

如何为 Mongodb 设计通知架构

如果我将所有用户的通知存储在一个集合下是否更好:

{
id_: Object,
type: String, // post or message
ref_id: Number, // post id or message id
owner: Number,
read: Boolean,
created_at: Date 
}

// when I get notification for a single user
db.notifications.find({"owner": user_id, "read": {$ne: true}})
Run Code Online (Sandbox Code Playgroud)

如果您有示例,请给我一些建议或一些学习链接。

谢谢。

schema mongodb

4
推荐指数
1
解决办法
6519
查看次数

如何在 node.js express 中获取 IP 地址

我们如何从 node.js 获取 ip 地址我尝试了很多方法但它不起作用并返回 ::ffff:127.0.0.1 请给我一些建议

这是我的代码:

app.put('/update-user-info', function(req, res){
  // it's doesn't work and return ::ffff:127.0.0.1
  var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress ||  req.socket.remoteAddress || req.connection.socket.remoteAddress; 
});
Run Code Online (Sandbox Code Playgroud)

node.js express

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

express ×1

mongodb ×1

node.js ×1

schema ×1