2014-04-28 11:45:59 -04:00
|
|
|
{db, ObjectId} = require "./mongojs"
|
|
|
|
|
|
|
|
module.exports = MongoManager =
|
|
|
|
findProject: (project_id, callback = (error, project) ->) ->
|
|
|
|
db.projects.find _id: ObjectId(project_id.toString()), {}, (error, projects = []) ->
|
2014-04-28 12:43:19 -04:00
|
|
|
callback error, projects[0]
|
|
|
|
|
2014-06-05 08:29:50 -04:00
|
|
|
findDoc: (doc_id, callback = (error, doc) ->) ->
|
|
|
|
db.docs.find _id: ObjectId(doc_id.toString()), {}, (error, docs = []) ->
|
|
|
|
callback error, docs[0]
|
|
|
|
|
2014-05-16 08:06:35 -04:00
|
|
|
updateDoc: (project_id, docPath, lines, callback = (error) ->) ->
|
2014-04-28 12:43:19 -04:00
|
|
|
update =
|
|
|
|
$set: {}
|
|
|
|
$inc: {}
|
|
|
|
update.$set["#{docPath}.lines"] = lines
|
|
|
|
update.$inc["#{docPath}.rev"] = 1
|
|
|
|
|
2014-04-29 10:07:22 -04:00
|
|
|
db.projects.update _id: ObjectId(project_id), update, callback
|
|
|
|
|
2015-01-20 12:09:51 -05:00
|
|
|
upsertIntoDocCollection: (project_id, doc_id, lines, oldRev, callback)->
|
|
|
|
update =
|
|
|
|
$set:{}
|
|
|
|
update.$set["lines"] = lines
|
|
|
|
update.$set["project_id"] = ObjectId(project_id)
|
|
|
|
update.$set["rev"] = oldRev + 1
|
|
|
|
db.docs.update _id: ObjectId(doc_id), update, {upsert: true}, callback
|
|
|
|
|
|
|
|
|
|
|
|
markDocAsDeleted: (doc_id, callback)->
|
|
|
|
update =
|
|
|
|
$set: {}
|
|
|
|
update.$set["deleted"] = true
|
|
|
|
db.docs.update _id: ObjectId(doc_id), update, (err)->
|
|
|
|
callback(err)
|