-
-
Save masahitojp/2049628 to your computer and use it in GitHub Desktop.
mongoDBの検証用
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// query | |
var query={ | |
"updated_time" : { | |
"$gte" : ISODate("2012-01-09T00:00:00Z"), | |
"$lte" : ISODate("2012-01-10T00:00:00Z") | |
} | |
} | |
// 1500件データ投入 | |
var JSTDate = function(str) { return ISODate(str + 'T00+09:00'); }; | |
var files = []; | |
for(var i=0;i<30;i++){files.push(hex_md5(Math.random().toString()));} | |
for(var i=1;i<=50;i++){ | |
for(var j=0;j<30;j++){ | |
db.files.save({"folder_path" : "", "file_id" : new ObjectId(), "file_name" : "no_" + i + ".wld", "updated_time" : ISODate("2012-01-" + ("0" + (j/2|0)).slice(-2)), "revision_number" : j }); | |
} | |
} | |
db.files.ensureIndex({"file_id":1, "branch_id":1, "revision_number":1},{unique:true}); | |
db.files.ensureIndex({"branch_id":1, "revision_number":1, "folder_path":1, "file_name":1}, {unique:true}); | |
// db.files.ensureIndex({"updated_time":1}); | |
// 結果の集計 | |
function test(){ | |
var a =0; | |
var cur = db.system.profile.find({"ns":"test.files"}).sort({$natural:-1}) ; | |
var cnt = db.system.profile.find({"ns":"test.files"}).count(); | |
cur.forEach(function(x){a+=x.millis}) | |
print(cnt) | |
print(a/cnt) | |
} | |
// Profile結果を破棄 | |
function clearProfile(){ | |
db.setProfilingLevel(0); | |
db.system.profile.drop(); | |
db.createCollection("system.profile", {capped:true, size:4000000}) | |
db.system.profile.stats() | |
db.setProfilingLevel(2); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pymongo import Connection | |
from datetime import datetime | |
connection = Connection('localhost', 27017) | |
# 'test' correct to Collection name | |
db=connection.test | |
files = db.files | |
gte = datetime(2012,1,10) | |
lte = datetime(2012,1,10) | |
for i in xrange(10000): | |
for file in files.find({"updated_time": {"$gte":gte, "$lte" : lte}}): | |
file | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment