1

I am developing in vb.net

Dim dtDetails As DataTable = Utility.GetDetailsTable()
Dim resource_id As String = ""

Dim dtrow = dtDetails.Select("id='" & user_id & "'")
If dtrow.Length > 0 Then
    For i As Integer = 0 To dtrow.Length - 1
       If i > 0 Then
          resource_id += ","
       End If
       resource_id += Convert.ToString(dtrow(i)("instance_id"))
    Next

but when I use resource_id further, it is not working, Docs returns as empty

Dim resource_ids = New BsonValue() {resource_id}
Dim querys = Query.And(
    Query.EQ("user_id", user_id),
    Query.In("resource_id", resource_ids)
)

Dim Docs = ceilometer.GetCollection("meter").Find(querys)

because I need it in this format BsonValue(){"resource_id1","resource_id2"}. Please help me to solve this

chridam
  • 100,957
  • 23
  • 236
  • 235
Syed Md. Kamruzzaman
  • 979
  • 1
  • 12
  • 33

1 Answers1

1

From how I understood your question, I believe you need to add the dynamic ids to the BsonValue array. Using an extension from this answer:

<Extension()> _
Public Sub Add(Of T)(ByRef arr As T(), item As T)
    Array.Resize(arr, arr.Length + 1)
    arr(arr.Length - 1) = item
End Sub

Which you can then use in your code as:

Dim dtDetails As DataTable = Utility.GetDetailsTable()
Dim resource_ids As new BsonArray

Dim dtrow = dtDetails.Select("id='" & user_id & "'")
If dtrow.Length > 0 Then
    For i As Integer = 0 To dtrow.Length - 1
       resource_ids.Add(Convert.ToString(dtrow(i)("instance_id")))
    Next
End If

Dim queries = Query.And(
    Query.EQ("user_id", user_id),
    Query.In("resource_id", resource_ids)
)

Dim Docs = ceilometer.GetCollection("meter").Find(queries)
Community
  • 1
  • 1
chridam
  • 100,957
  • 23
  • 236
  • 235