Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to query mongodb with like?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 260
    Comment on it

    Hello All,


    In this blog we will discuss about how to query mongodb with "like".

    In MySql you might have normally used below code to find by like

    select * from users where name like '%text%'
    

    But for using like in mongoDb you have to write in below code:-

    You can use the actual regex object via MongoRegex

    db.collection_name.find({'field': {'$regex': 'yourtext'}})
    

    Below is the demonstration-

    Example

    We want to find the kiTAG like connect#evontech.com from collection keytags. So below is how you query mongoDb:

    > db.keytags.find({'kiTAG': {'$regex': 'connect#evontech.com'}})
    

    Output

    {
        "__v" : 0,
        "_id" : ObjectId("56499d341af7854313c2fb8a"),
        "additionalProperties" : {
            "wifiTagDescription" : "",
            "networkType" : "WEP",
            "password" : "Ankit11",
            "ssid" : "ankit.chettri%40evontech.com"
        },
        "businessId" : ObjectId("55c337720545813123acf09f"),
        "clientId" : ObjectId("55c33660cfc3bb56068b4567"),
        "createdAt" : ISODate("2015-11-16T09:09:08.923Z"),
        "creatorAccountId" : ObjectId("55c3366672a63c6a2246af3e"),
        "dataChecksum" : "3d794b6847d0e7b2fcc355462b2e1d95",
        "deleted" : "false",
        "domain" : "evontech.com",
        "donotIndex" : false,
        "isDomainCard" : true,
        "kiTAG" : "connect#evontech.com",
        "lastIndexedOn" : null,
        "manualUpdate" : true,
        "name" : "connect",
        "relatedKeywords" : "",
        "seo" : true,
        "status" : "ACTIVE",
        "title" : "TEST",
        "type" : "Wi-Fi",
        "updatedAt" : ISODate("2014-12-17T06:17:17.461Z")
    }
    > 
    > 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: