Created
August 4, 2012 09:36
-
-
Save ajaxray/3256391 to your computer and use it in GitHub Desktop.
Data generating for integration testing in MongoDb application
This file contains 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
function removeAll() { | |
var names = db.getCollectionNames(); | |
for(var i = 0; i < names.length; i++) { | |
if(names[i] == "system.indexes") continue; | |
db[names[i]].dropIndexes(); | |
db[names[i]].remove({}); | |
//db[names[i]].drop(); | |
} | |
} | |
removeAll(); | |
// Call from shell as: | |
// mongo database_name /path/of/clearDb.js |
This file contains 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
db.copyDatabase("socialmaps_test_backup", "socialmaps_test"); | |
// Call from shell as: | |
// mongo database_name /path/of/copyDb.js |
This file contains 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
/** deals indexes **/ | |
db.getCollection("deals").ensureIndex({ "_id": NumberInt(1) },[]); | |
db.getCollection("deals").ensureIndex({ "location": "2d" }); | |
/** deals records **/ | |
db.getCollection("deals").insert({ | |
"_id": ObjectId("500ed567757df23105000001"), | |
"title": "A football club in Dhaka", | |
"description": "I have not tried removing the extends Base, but I'm curious as to why that would affect the outcome of the query. Base is an Abstract class I made just to handle some simple operations common to all models. I'm able to run other queries against ODM with stellar success.", | |
"link": "http://www.bracbank.com/", | |
"maplink": "https://maps.google.com/maps?f=d&source=s_d&saddr=Dhaka,+Bangladesh&daddr=&hl=en&geocode=CZUgR70GmSI1FeHIaQEd54BjBSmBawKHsLhVNzHCBFndu2Oljw&sll=23.709924,90.407138&sspn=0.021847,0.040555&vpsrc=6&mra=mift&ie=UTF8&t=m&z=15&iwloc=ddw0", | |
"category": "sports", | |
"location": { | |
"lng": 80.05, | |
"lat": 90.05 | |
}, | |
"createDate": ISODate("2012-07-24T17:03:35.0Z") | |
}); | |
// More collections and records as known data set... |
This file contains 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
<?php | |
use \Doctrine\ODM\MongoDB\DocumentManager; | |
define('API_BASEURL', 'http://api.example.local/index_test.php'); | |
function prepareBackupDatabase() | |
{ | |
exec("mongo socialmaps_test_backup ". __DIR__. "/scripts/clearDb.js"); | |
exec("mongo socialmaps_test_backup ". __DIR__. "/scripts/prepareBackup.js"); | |
} | |
function clearDatabase() { | |
exec("mongo socialmaps_test ". __DIR__. "/scripts/clearDb.js"); | |
} | |
function restoreDatabase() { | |
exec("mongo socialmaps_test ". __DIR__. "/scripts/copyDb.js"); | |
} | |
// Other helper functions... | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment