Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial MongoStore added

  • Loading branch information...
commit 7c06b66b91e7a31d7a6b18835a200ef9ad162c0d 1 parent bbbf944
Michael Hughes authored
View
36 src/server/MongoStore.coffee
@@ -0,0 +1,36 @@
+mongo = require 'mongodb'
+
+entryCollection = "entryData"
+
+exports.createMongostore = (connectionString)->
+
+ connect:(fun)->
+ mongoClient = mongo.MongoClient
+ mongoClient.connect connectionString,(err,db)->
+ fun err,null if err
+ fun null,db.collection(entryCollection) unless err
+
+ clear:(fun)->
+ @connect (err,collection)->
+ if err then fun err,null
+ else
+ collection.remove {},fun
+
+ count:(fun)->
+ @connect (err,collection)->
+ if err then fun err,null
+ else
+ collection.count fun
+
+ insert:(data,fun)->
+ @connect (err,collection)->
+ if err then fun err,null
+ else
+ collection.insert data,{w:1},fun
+
+ getEntries:(search,fun)->
+ @connect (err,collection)->
+ if err then fun err,null
+ else
+ collection.find(search).toArray fun
+
View
23 test/server/integration/MongoStore_test.coffee
@@ -0,0 +1,23 @@
+mongostore = require '../../../src/server/MongoStore.coffee'
+expect = (require 'chai').expect
+
+connectionString = "mongodb://localhost:27000/feeds"
+
+feedData = [
+ {"title":"A news story","link":"http://a.news.story/"}
+ {"title":"Another news story","link":"http://another.news.story/"}
+ ]
+
+describe 'A mongodb store', ->
+ beforeEach (done) ->
+ @ms = mongostore.createMongostore(connectionString)
+ @ms.clear (err,result)->
+ done()
+
+ it 'should be able to insert data into the datastore', (done)->
+ @ms.insert {"title":"An interesting tech story","link":"http://tech/story"},(err,result)=>
+ throw err if err
+ expect(result[0].title).to.equal("An interesting tech story")
+ expect(result[0]._id).to.exist
+ done()
+
Please sign in to comment.
Something went wrong with that request. Please try again.