Dynamically creating a query in documentDb

So, I searched all morning, but could not find a satisfactory answer

I am trying to write a general method (service) that takes an object as input (maybe a JObject or Document or dynamic) and requests a collection for the properties of the object.

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

Question. What should be the best input for the method? Options - 1. public bool Exists (Document doc) // Suppose I already have a Collection.Selflink class. I can't seem to iterate over the properties of a doc object.

  1. public bool Exists (JObject obj) I will need to go through obj and prepare the request myself.

Is there an easier way to just see if a document matches any of the documents in the collection. I'm just interested in matching the fields that are contained in the document.

Thanks in advance!

+5
source share
1 answer

This is not supported out of the box.

I would suggest that some custom code that repeats over the object passed and added by each property to the where clause in SQL or Linq is likely to solve the problem.

It may start to get confused with nested objects and arrays.

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

+3
source

All Articles