mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
5861231548
- need to run migration 1 before using this for this to work - added acceptence test so new documents updated should be upserted, not return 404
26 lines
796 B
CoffeeScript
26 lines
796 B
CoffeeScript
{db, ObjectId} = require "./mongojs"
|
|
|
|
module.exports = MongoManager =
|
|
|
|
findDoc: (doc_id, callback = (error, doc) ->) ->
|
|
db.docs.find _id: ObjectId(doc_id.toString()), {}, (error, docs = []) ->
|
|
callback error, docs[0]
|
|
|
|
getProjectsDocs: (project_id, callback)->
|
|
db.docs.find project_id: ObjectId(project_id.toString()), {}, callback
|
|
|
|
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)
|