0

I Think I've got some weird situation here. Hmm, dunno if I can't do something like these below.

The 1st Query without regex

db.Books.find(
{attributes: { $all: [ 
{'value_string':'bwOBtHQx','ref':ObjectId("5199ec31d005602b8b000000")},
{'value_string':'ikigzuy','ref':ObjectId("5211d045d005609a65000000")},
{'value_boolean':true,'ref':ObjectId("5199ec7bd005602c8b000002")} ] }
}).explain()

This query resulting one record exactly.

The 2nd Query with regex on value_string field.

db.Books.find(
{attributes: { $all: [ 
{'value_string':'bwOBtHQx','ref':ObjectId("5199ec31d005602b8b000000")},
{'value_string':/iki.*/,'ref':ObjectId("5211d045d005609a65000000")},
{'value_boolean':true,'ref':ObjectId("5199ec7bd005602c8b000002")} ] }
}).explain()

This query doesn't fetch anything. I think it should show the same result as the first one

Example of a Books record.

{"id":ObjectId("xxxxxxxxxxxxxxxxx"),
 "attributes" : [ 
                 { "value_string" : "bwOBtHQx",
                   "ref" : ObjectId( "5199ec31d005602b8b000000" ) }, 
                 { "value_string" : "ikigzuy",
                   "ref" : ObjectId( "5211d045d005609a65000000" ) }, 
                 { "value_boolean" : true,
                   "ref" : ObjectId( "5199ec7bd005602c8b000002" ) } ]
}

nb:

  1. The "attributes" field is already indexed.
  2. "attributes" is an Embedded Document(s) in Many relationship.
  3. It works when I use $in operator, but not exactly match the elements I'm looking for.

Is there any alternative?

4

0 回答 0