Hallo,
I am writing a large social network on node.js and mongodb (mongoose module). That mean there will be many users and large data in database.
I have created user registration and now i need to allow users write private messages to each other.
Questions:
1) how should i store data about sending private messages? i have thought 2 ways:
first
var schemaUser = new mongoose.Schema({
i: Number,
...
message: { type: Schema.ObjectId, ref: 'Message' }
});
var schemaMessage = new mongoose.Schema({
m: [{
f: Number, // value i from schemaUser, means from user
m: String, // message
d: { type: Date, default: Date.now } // date
}]
});
module.exports = {
User: db.model('User', schemaUser),
Message: db.model('Message', schemaMessage)
}
In this way every user has message
field to Message
table, where he has only one collection m
, where in array stores all messages.
second
I store in Messages
all messages like this:
var schemaMessage = new mongoose.Schema({
t: Number, // means to what user this messages sent
f: Number, // value i from schemaUser, means from what user message sent
m: String, // message
d: { type: Date, default: Date.now } // date
});
All messages are mixed in one table. But as i understood, the disadvantage of this method is that there are might be more than million private messages in database, and that is why the speed and performance to find messages from
user and to
user was sent will be bad. when on first method all messages are in array.
So, which way should i choose or any other ideas?
2) I have array like on first method: var arr = []
question: how many objects can i put in arr
? what is the size of arr
? for example, if i push something like arr.push({t: #, f: #, m: 'message...'})
?