llmongodb/day_init.js
2018-06-06 17:28:03 +02:00

8 lines
No EOL
458 B
JavaScript

var db = connect("192.168.0.1:27017/lastlogin");
//var conn = new Mongo("192.168.0.1");
//var db = conn.getDB("lastlogin");
var dd = function(x) { var s = x.toString(); if(s.length > 1){return s;} else { return "0"+s;}}
var now = new Date();
var col = now.getFullYear() + dd(now.getMonth()+1) + dd(now.getDate())
print("creating index: ll_"col.slice(2));
db.getCollection("ll_"+col.slice(2)).createIndexes([{"date": 1},{"country": 1},{"user": 1,"date": -1}])