none
How can i use $regex to search in an array ? RRS feed

  • Question

  • We have document with array SearchserviceStreet, we want to use regex to search in it. I tried different variation but wasn't able to successfully search through it.

    Can you please help me ?

    Thx

    {
    "_id" : 70481,
    "UtilityID" : 1021,
    "CustomerID" : 70481,
    "AccountNumber" : "200026846840-0400134732",
    "OccupantCode" : null,
    "ClientEntityLookupDisplayName" : "Business",
    "BusinessNumber" : "400134732",
    "MeterNumber" : "2",
    "Name" : "000000000 Ontario Inc",
    "ExternalLocationID" : "700736718",
    "BusinessOperatingName" : null,
    "IsActive" : true,
    "RateCode" : "Urban Gen Svc Energy 2TIER RPP",
    "TimeFrame" : "",
    "Ranking" : "",
    "Tenancy" : "Owner",
    "NAICS" : null,
    "NAICSDescription" : null,
    "SIC" : null,
    "SICDescription" : null,
    "serviceStreet" : "1111 SANDHILL DR ",
    "ServiceCity" : "BBBBBBB",
    "ServicePostCode" : "M1M8M8",
    "ServiceProvince" : "ON",
    "mailingStreet" : "1111 SANDHILL DR",
    "mailingCity" : "BBBBBB",
    "mailingPostCode" : "M1M8M8",
    "mailingProvince" : "ON",
    "BusinessPhone" : "1111111111        ",
    "BusinessExtension" : null,
    "FaxNumber" : "",
    "HeatType" : "",
    "WaterHeatType" : "",
    "BuildingType" : "",
    "kWH" : null,
    "Kw" : null,
    "Kva" : null,
    "Pf" : null,
    "BuildingYear" : null,
    "IsFlaggedForMailing" : false,
    "SA_MA" : null,
    "CommunicationGroup" : null,
    "SalesPerson" : "",
    "HasSignedRetailerContract" : false,
    "RetailerName" : null,
    "RetailerContractSignedDate" : null,
    "PrimaryContactName" : "Zelko ",
    "PrimaryTitle" : "Mr.",
    "PrimaryPhone" : "1111111111    ",
    "Email" : null,
    "lastModified" : {
    "$date" : 1529803322690
    },
    "MACodeId" : 0,
    "MaxDemand" : null,
    "AverageDemand" : null,
    "MaxMonthlyUsage" : null,
    "AverageMonthlyUsage" : null,
    "IsActiveFixed" : true,
    "MoveInDate" : null,
    "MeterInstallDate" : null,
    "EmployeeNumber" : null,
    "YearEstablished" : "",
    "URL" : null,
    "OperationSize" : null,
    "MailingCustomerName" : null,
    "SubSegment" : null,
    "PrimaryJobFunction" : "Management",
    "CustomerIdString" : "     70481",
    "ThirdSegment" : null,
    "YearlyAverageBill" : null,
    "SecondaryContactName" : "",
    "SecondaryContactTitle" : "",
    "SecondaryContactPhone" : "",
    "SecondaryContactEmail" : "",
    "SecondaryJobFunction" : "",
    "ThirdContactName" : "",
    "ThirdContactTitle" : "",
    "ThirdContactPhone" : "",
    "ThirdContactEmail" : "",
    "ThirdJobFunction" : "",
    "EnergyUsePerSqFt" : 0,
    "CallCenterFunction" : 6,
    "ProjectCommunicationCount" : 0,
    "StatusName_SBLCFF" : "To Be Contacted",
    "OFANumber" : null,
    "CustomerImportTypeId" : 1,
    "CustomerEmail" : "",
    "ResidentPhone" : "1111111111        ",
    "SecondaryPhone" : "",
    "TotalRecords" : 0,
    "BRIStatus" : "Dismissed",
    "SearchserviceStreet" : [
    "11111",
    "sandhill",
    "dr",
    ""
    ],
    "SearchServiceCity" : "11111111",
    "SearchServicePostCode" : 111111",
    "SearchRateCode" : "urban gen svc energy 2tier rpp",
    "SearchMeterNumber" : "2",
    "SearchBusinessOperatingName" : "",
    "SearchmailingCity" : "ancaster",
    "SearchBusinessPhone" : "1111111",
    "SearchPrimaryPhone" : "111111111",
    "SearchName" : "000000000 ontario inc",
    "SearchSplitName" : [
    "000000000",
    "ontario",
    "inc"
    ],
    "SearchSubSegment" : null
    }

    Tuesday, May 14, 2019 8:29 PM

All replies

  • Hi Balwinder,

    Could you please try below code snippet:

    var thisExpressions = [/something/, /something_else/, /and_something_else/];
    var thisExpressions2 = [/else/, /something_else/, /and_something_else/];
    var thisString = 'else';
    
    function matchInArray(string, expressions) {
    
        var len = expressions.length,
            i = 0;
    
        for (; i < len; i++) {
            if (string.match(expressions[i])) {
                return true;
            }
        }
    
        return false;
    
    };
    
    setTimeout(function() {
        console.log(matchInArray(thisString, thisExpressions));
        console.log(matchInArray(thisString, thisExpressions2));
    }, 200)​

    Reference StackOverFlow Thread for the same.

    Hope this will help resolve your problem.

    Wednesday, May 15, 2019 9:50 AM
    Moderator
  • Sorry forgot to mention that I am trying it in c# using mongodriver Azure Cosmo Db (mongo).
    Wednesday, May 15, 2019 1:00 PM
  • Hi,

    Any help?

    Thursday, September 5, 2019 8:30 PM
  • Hi BalwinderS,

    At this point, given the time span of this issue, can you reach out directly to AskCosmosMongoAPI and they should be able to provide the most update to date status of the Mongo API service and any limitations that are currently in place. Please do post any feedback or resolution they provide as this information will assist others who are attempting to implement a similar solution. Thank you!

    Regards,

    Mike

    Monday, September 9, 2019 6:20 PM
    Moderator