Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a query dynamically in documentDb

So I searched whole morning but couldn't find satisfactory answer

I am trying to write a generic method (service) which take an object as an input (can be JObject or Document or dynamic) and queries the collection for the properties in the object.

Example - if you send {"name": "abc"} I will search for name="abc" in any of the documents. if you send {"name":"abc", "department":"xyz"}, it searches on both fields.

Question - what should be the best input for the method? Options - 1. public bool Exists(Document doc) //assume I already have Collection.Selflink the class. I cannot seem to iterate through properties of the doc object.

  1. public bool Exists(JObject obj) I will have to iterate through the obj and prepare the query myself.

Is there any easier way to just see if the doc matches any of the documents in the collection. I am just interested in matching those fields present in the document.

Thanks in advance!

like image 393
Abhishek Avatar asked Jul 30 '15 19:07

Abhishek


Video Answer


1 Answers

This isn't supported out of the box.

I would imagine a bit of custom code that iterated over the object passed in and appended each property to a where clause in SQL or Linq would likely solve the problem.

It could start to get messy with nested objects and arrays though.

If this is something you would like to see supported natively, please vote for it http://feedback.azure.com

like image 171
Ryan CrawCour Avatar answered Oct 15 '22 12:10

Ryan CrawCour