c# - How to convert deprecated IMongoQuery to a FilterDefinitionBuilder -


i've got visual studio c# project that's using mongodb driver v2.0, , attempting update use driver v2.3.0.

there's section of code builds list of imongoquery entries based on presence of various search fields, e.g.

var querylist = new list<imongoquery>(); if (!string.isnullorempty(searchfield1))   querylist.add(query.matches(skey1, searchfield1)); ... if (!string.isnullorempty(searchfieldn))   querylist.add(query.matches(skeyn, searchfieldn)); 

how convert new filterdefinitionbuilder syntax? don't see similar add() method in interface.

update:

here's i'm doing, , ugly! please let me know if there's better way this.

var builder = builders<bsondocument>.filter; filterdefinition<bsondocument> filter = null;  // each search field if (!string.isnullorempty(searchfield1)) {   if (filter == null)     filter = builder.eq(skey1, searchfield1);   else     filter = filter & builder.eq(skey1, searchfield1); } 


Comments

  1. i have the same problem here after updating the mongodriver to latest ver

    ReplyDelete

Post a Comment

Popular posts from this blog

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

mysqli - Php Mysqli_fetch_assoc Error : "Warning: Illegal string offset 'name' in" -

javascript - Chart.js - setting tooltip z-index -