B4J Question AND in MongoDB

Discussion in 'B4J Questions' started by Hanz, Oct 28, 2018.

Tags:
  1. Hanz

    Hanz Member

    Hello,

    I am trying to query a record from a collection, "employees". The query is to find a record which _id is 1 and the name is Dev. I used the statement below:

    Dim emplist3 As List = employees.Find(CreateMap("$and" : CreateMap("_id":1, "name":"Dev")),Null,Null)

    But it says something that the $and must be an array. Thus, I used the statement below:

    Dim emplist3 As List = employees.Find(Array(CreateMap("$and" : CreateMap("_id":1, "name":"Dev"))),Null,Null)

    But the above generates an error which says something like,
    Dim emplist3 As List = employees.Find(Array(Crea
    javac 1.8.0_152
    src\b4j\example\main.java:100: error: incompatible types: Object[] cannot be converted to Map

    What is wrong with the above codes?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Please use [code]code here...[/code] tags when posting code.

    Try:
    Code:
    Dim emplist3 As List = employees.Find(CreateMap("$and" : Array(CreateMap("_id":1), CreateMap("name":"Dev"))),Null,Null)
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    Better:
    Code:
    Dim emplist3 As List = employees.Find(CreateMap("$and" : _
           
    Array( _
               CreateMap(
    "_id":1), _
               CreateMap(
    "name":"Dev") _
               ) _
           ) _
           ,
    Null,Null)
     
    Peter Simpson likes this.
  4. Hanz

    Hanz Member

    It's working perfectly now... Thank you very much for the reply.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice