Fixed ability to query tasks collection using task ID. Fixes #68.
This commit is contained in:
1 parent
7c8036d8f3
commit
6f595b6fc5
2 files changed
+27
No files matched your search
@@ -348,6 +348,7 @@ listener = (request, response) ->
|
|||||||
else
|
else
|
||||||
q = {}
|
q = {}
|
||||||
q = query.expand(q, aliases) if collectionName is 'devices'
|
q = query.expand(q, aliases) if collectionName is 'devices'
|
||||||
|
q = query.substituteObjectId(q) if collectionName is 'tasks'
|
||||||
|
|
||||||
if urlParts.query.projection?
|
if urlParts.query.projection?
|
||||||
projection = {}
|
projection = {}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
common = require './common'
|
common = require './common'
|
||||||
normalize = require './normalize'
|
normalize = require './normalize'
|
||||||
|
mongodb = require 'mongodb'
|
||||||
|
|
||||||
|
|
||||||
expandValue = (param, value) ->
|
expandValue = (param, value) ->
|
||||||
@@ -103,5 +104,30 @@ expand = (query, aliases) ->
|
|||||||
|
|
||||||
return new_query
|
return new_query
|
||||||
|
|
||||||
|
# Replace _id string values with ObjectID type
|
||||||
|
substituteObjectId = (query) ->
|
||||||
|
for k, v of query
|
||||||
|
if k[0] == '$' # logical operator
|
||||||
|
for i in [0...v.length]
|
||||||
|
substituteObjectId(v[i])
|
||||||
|
else if k == '_id'
|
||||||
|
if common.typeOf(v) is common.STRING_TYPE
|
||||||
|
query[k] = mongodb.ObjectID(v) if v.length == 24
|
||||||
|
else if common.typeOf(v) is common.OBJECT_TYPE
|
||||||
|
for kk, vv of v
|
||||||
|
switch kk # operator
|
||||||
|
when '$in', '$nin'
|
||||||
|
for i in [0...vv.length]
|
||||||
|
vv[i] = mongodb.ObjectID(vv[i]) if vv[i].length == 24
|
||||||
|
when '$eq', '$gt', '$gte', '$lt', '$lte', '$ne'
|
||||||
|
v[kk] = mongodb.ObjectID(vv) if vv.length == 24
|
||||||
|
when '$exists', '$type' then
|
||||||
|
# ignore
|
||||||
|
else
|
||||||
|
throw new Error('Operator not supported')
|
||||||
|
|
||||||
|
return query
|
||||||
|
|
||||||
|
|
||||||
exports.expand = expand
|
exports.expand = expand
|
||||||
|
exports.substituteObjectId = substituteObjectId
|
||||||
Reference in new issue
Block a user