1

How to pass Object to MongoDb query builder?

public IMongoQuery Equals(string name,object value){
    return Query.EQ(name, **value**); //compilation error, 
                                     //no overloaded method and no implicit overloading 
                                    //operator for object
}

If we are just passing primitive variables int, double etc. they have overloaded implicit operator in BsonValue class for all primitive types. I wondered if there's a way to achieve this.

1 Answer 1

1

Try this:

public IMongoQuery Equals(string name, object value)
{
   var val = BsonValue.Create(value);
   return Query.EQ(name, val);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.