Regex matching seems ignore the `:` ?

15 views
Skip to first unread message

greenl

unread,
Apr 25, 2017, 1:21:27 AM4/25/17
to Morphia
Here is my mongodb shell session

> db.foo.save({path: 'a:b'})
WriteResult({ "nInserted" : 1 })
> db.foo.findOne()
{ "_id" : ObjectId("58fedc47622e89329d123ee8"), "path" : "a:b" }
> db.foo.save({path: 'a:b:c'})
WriteResult({ "nInserted" : 1 })
> db.foo.find({path: /a:[^:]+/})
{ "_id" : ObjectId("58fedc47622e89329d123ee8"), "path" : "a:b" }
{ "_id" : ObjectId("58fedc57622e89329d123ee9"), "path" : "a:b:c" }
> db.foo.find({path: /a:[a-z]+/})
{ "_id" : ObjectId("58fedc47622e89329d123ee8"), "path" : "a:b" }
{ "_id" : ObjectId("58fedc57622e89329d123ee9"), "path" : "a:b:c" }

Clearly the regex /a:[^:]+/ and /a:[a-z]+/ shall not match 'a:b:c', but looks like mongo failed on this regex, does anyone know what happened here?

greenl

unread,
Apr 25, 2017, 1:50:46 AM4/25/17
to Morphia
Sorry please ignore the this thread. Just realized it is not a morphia issue. 
Reply all
Reply to author
Forward
0 new messages