Created
October 15, 2012 18:20
-
-
Save Jedt3D/3894133 to your computer and use it in GitHub Desktop.
MongoDB + OpenBlueDragon for GridFS
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 testAddRemoveFindOne(){ MongoRegister( name="mongo", server="127.0.0.1", db="openbd" ); var id = MongoGridfsSave( "mongo", "filebucket", ExpandPath("MongoDatabase.cfc"), "mongodatabase.cfc", "text/plain", "4f6e7d23c243305d41cd748c", {custom1:1, custom2:"age"} ); var f = MongoGridfsFindOne(datasource="mongo", bucket="filebucket", _id=id); assertEquals( f._id, "4f6e7d23c243305d41cd748c" ); assertEquals( f.filename, "mongodatabase.cfc" ); assertEquals( f.contentType, "text/plain" ); assertTrue( f.length > 0 ); assertEquals( f.metadata.custom1, 1 ); assertEquals( f.metadata.custom2, "age" ); // Delete it from the database MongoGridfsRemove( datasource="mongo", bucket="filebucket", _id=id ); f = MongoGridfsFindOne(datasource="mongo", bucket="filebucket", _id=id); assertTrue( StructCount(f) == 0 ); } // --------------------------------------------------------------------------------- function testAddFindRemove(){ MongoRegister( name="mongo", server="127.0.0.1", db="openbd" ); var id = MongoGridfsSave( "mongo", "filebucket", ExpandPath("MongoDatabase.cfc"), "mongodatabase.cfc", "text/plain", "4f6e7d23c243305d41cd748c", {custom1:1, custom2:"age"} ); var arry = MongoGridfsFind(datasource="mongo", bucket="filebucket", query={filename:"mongodatabase.cfc"} ); assertTrue( ArrayLen(arry) == 1 ); // Delete it from the database MongoGridfsRemove( datasource="mongo", bucket="filebucket", _id=id ); f = MongoGridfsFindOne(datasource="mongo", bucket="filebucket", _id=id); assertTrue( StructCount(f) == 0 ); } // --------------------------------------------------------------------------------- function testAddGetRemove(){ MongoRegister( name="mongo", server="127.0.0.1", db="openbd" ); var id = MongoGridfsSave( "mongo", "filebucket", ExpandPath("MongoDatabase.cfc"), "mongodatabase.cfc", "text/plain", "4f6e7d23c243305d41cd748c", {custom1:1, custom2:"age"} ); var res = MongoGridfsGet(datasource="mongo", bucket="filebucket", filepath=ExpandPath('deleteme.cfc'), _id=id ); assertTrue( res ); FileDelete( ExpandPath('deleteme.cfc') ); // Delete it from the database MongoGridfsRemove( datasource="mongo", bucket="filebucket", _id=id ); f = MongoGridfsFindOne(datasource="mongo", bucket="filebucket", _id=id); assertTrue( StructCount(f) == 0 ); } |
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 testAddRemoveFindOne() { | |
MongoRegister(name = "mongo", server = "127.0.0.1", db = "openbd"); | |
var id = MongoGridfsSave("mongo", "filebucket", ExpandPath("MongoDatabase.cfc"), "mongodatabase.cfc", "text/plain", "4f6e7d23c243305d41cd748c", {custom1:1, custom2:"age"}); | |
var f = MongoGridfsFindOne(datasource = "mongo", bucket = "filebucket", _id = id); | |
assertEquals(f._id, "4f6e7d23c243305d41cd748c"); | |
assertEquals(f.filename, "mongodatabase.cfc"); | |
assertEquals(f.contentType, "text/plain"); | |
assertTrue(f.length > 0); | |
assertEquals(f.metadata.custom1, 1); | |
assertEquals(f.metadata.custom2, "age"); | |
// Delete it from the database | |
MongoGridfsRemove(datasource = "mongo", bucket = "filebucket", _id = id); | |
f = MongoGridfsFindOne(datasource = "mongo", bucket = "filebucket", _id = id); | |
assertTrue(StructCount(f) == 0); | |
} | |
// --------------------------------------------------------------------------------- | |
function testAddFindRemove() { | |
MongoRegister(name = "mongo", server = "127.0.0.1", db = "openbd"); | |
var id = MongoGridfsSave("mongo", "filebucket", ExpandPath("MongoDatabase.cfc"), "mongodatabase.cfc", "text/plain", "4f6e7d23c243305d41cd748c", {custom1:1, custom2:"age"}); | |
var arry = MongoGridfsFind(datasource = "mongo", bucket = "filebucket", query = {filename:"mongodatabase.cfc"}); | |
assertTrue(ArrayLen(arry) == 1); | |
// Delete it from the database | |
MongoGridfsRemove(datasource = "mongo", bucket = "filebucket", _id = id); | |
f = MongoGridfsFindOne(datasource = "mongo", bucket = "filebucket", _id = id); | |
assertTrue(StructCount(f) == 0); | |
} | |
// --------------------------------------------------------------------------------- | |
function testAddGetRemove() { | |
MongoRegister(name = "mongo", server = "127.0.0.1", db = "openbd"); | |
var id = MongoGridfsSave("mongo", "filebucket", ExpandPath("MongoDatabase.cfc"), "mongodatabase.cfc", "text/plain", "4f6e7d23c243305d41cd748c", {custom1:1, custom2:"age"}); | |
var res = MongoGridfsGet(datasource = "mongo", bucket = "filebucket", filepath = ExpandPath('deleteme.cfc'), _id = id); | |
assertTrue(res); | |
FileDelete(ExpandPath('deleteme.cfc')); | |
// Delete it from the database | |
MongoGridfsRemove(datasource = "mongo", bucket = "filebucket", _id = id); | |
f = MongoGridfsFindOne(datasource = "mongo", bucket = "filebucket", _id = id); | |
assertTrue(StructCount(f) == 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's not JavaScript but to make syntax highlight work a bit more. This ColdFusion Script is rename to .js