Skip to content

Instantly share code, notes, and snippets.

@krazylearner
Created September 15, 2016 14:23
Show Gist options
  • Save krazylearner/ee2e79824476b160875dd39532891283 to your computer and use it in GitHub Desktop.
Save krazylearner/ee2e79824476b160875dd39532891283 to your computer and use it in GitHub Desktop.
Testing the codument size with embedded array of 30000 Object ids
var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/my_databasetest');
var Schema = mongoose.Schema;
var ObjectId = Schema.Types.ObjectId;
var UserSchema = new Schema({
name: String,
friends: [{type: ObjectId}]
});
var User = mongoose.model('User', UserSchema);
var user = new User({ name: 'tes' });
for (var i = 0 ; i < 30000; ++i ){
user.friends.push(new mongoose.Types.ObjectId());
}
user.save(function (err) {
if (!err) {
console.log((JSON.stringify(user).length)/1024);
User.findOne({},function(err,user){
});
}else{
console.log(err);
}
});
// RESULT
// the size was 791.08 KB for 30000 OBject ids
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment