i using mongodb c# driver version 2.2. collection contains "parent" objects. each parent object has array of children objects. each child has name value:
"parent": { "children":[ { "name": "bob", "age": 10}, { "name": "alice", "age": 7}, { "name": "tobias", "age": 11} ] }
i need translate following code c# statements / linq syntax:
db.getcollection('parents').find({'parent.children': { $elemmatch: { 'name': { $regex: '.*ob.*', $options: 'im' } }}})
i have found there methods like
var builder = builders<bsondocument>.filter; builder.regex("parent.children.name", new bsonregularexpression(".*ob.*")); //does not work array
and
builder.anyeq("parent.children.name", "ob"); //without regex
but cannot understand how combine them. please advise.
update:
i using following now, please correct me if know reason why should not work correctly:
builder.anyeq("parent.children.name", new bsonregularexpression(".*ob.*"))
i using following now:
builder.anyeq("parent.children.name", new bsonregularexpression(".*ob.*"))
Comments
Post a Comment