Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Carlos
/
query-to-mongo
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9fd3807a
authored
Mar 29, 2017
by
Jose Carlos López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix criteria exception to a 12chars string conversion
parent
deb463f9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
2 deletions
lib/objectID.js
package.json
test/query.js
lib/objectID.js
View file @
9fd3807a
var
ObjectID
=
require
(
'bson'
).
ObjectID
;
var
objectIDRegex
=
new
RegExp
(
/^
[
0-9a-fA-F
]{24}
$/
);
module
.
exports
=
{
isObjectID
:
function
(
value
)
{
return
ObjectID
.
isValid
(
value
);
},
isObjectID
:
function
(
value
)
{
// NOTE We need to check that its a 24hex string because
// a 12 chars string is a valid objectID but we dont want it replaced
// by an objectid type
return
ObjectID
.
isValid
(
value
)
&&
objectIDRegex
.
test
(
value
);
},
toObjectID
:
function
(
value
)
{
return
ObjectID
(
value
);
}
};
package.json
View file @
9fd3807a
...
...
@@ -18,7 +18,7 @@
"test"
:
"node_modules/mocha/bin/mocha test"
},
"dependencies"
:
{
"
bson
"
:
"^
0.4.23
"
"
bson
"
:
"^
1.0.4
"
},
"publishConfig"
:
{
"registry"
:
"http://192.168.1.199:4873/"
...
...
test/query.js
View file @
9fd3807a
...
...
@@ -172,6 +172,11 @@ describe("query-to-mongo(query) =>", function () {
assert
.
ok
(
results
)
assert
.
deepEqual
(
results
,
{
d
:
ObjectID
(
'574553013b58d8582cdb1d5f'
)})
})
it
(
"should not create mongo objectID criteria fom a 12 chars string"
,
function
()
{
var
results
=
q2m
(
"d=llosaderanes"
)
assert
.
ok
(
results
)
assert
.
deepEqual
(
results
,
{
d
:
'llosaderanes'
})
})
})
describe
(
".options"
,
function
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment