I
I
iamsaint2013-07-05 12:18:00
MongoDB
iamsaint, 2013-07-05 12:18:00

MongoDB search for occurrence of specified digit in numeric field

Good afternoon.
Please tell me how to find the occurrence of the specified number in the numeric field in mongodb

> db.log.find();
{ "_id" : ObjectId("514de4657f15155d4f000009"), "date" : "23.01.2013", "user_id" : 1,  "show" : 8614 }
{ "_id" : ObjectId("514de4657f15155d4f000013"), "date" : "23.01.2013", "user_id" : 65,  "show" : 58 }
{ "_id" : ObjectId("51527f0d7f15155c28000016"), "date" : "23.01.2013", "user_id" : 14,  "show" : 361 }
...

> db.log.find({show: {$regex: /61/i}})

не возвращает результатов

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
iamsaint, 2013-07-05
@iamsaint

I already understood this :) I solved it like this:

db.log.find({$where : function() { return (/61/i).test(this.show)} })

M
Max, 2013-07-05
@7workers

regex will work if the field is a string and not an integer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question