title: How to check phone numbers stored in the phone against the firebase database?
body: <p>I am using firebase and swift. Once the user is signed in with FIRAuth, I get and validate the user's phone number complete with country code such as: +18585555555</p>
  
  <p>I store the username, logindate and phonenumber to the firebase db and use the phone as the KEY. This is the format:</p>
  
  <pre><code>  "users" : {
      "+18585555555" : {
        "lastLoginDate" : "2016.07.15 21:39:26 GMT+3",
        "name" : "John",
        "phone" : "+18585555555"
      },
      "+18585555556" : {
        "lastLoginDate" : "2016.07.15 15:46:16 GMT+3",
        "name" : "Jane",
        "phone" : "+18585555556"
      },
      "+18585555557" : {
        "lastLoginDate" : "2016.07.15 16:13:46 GMT+3",
        "name" : "Richard",
        "phone" : "+18585555557"
      }
    }
  }
  </code></pre>
  
  <p>I get the contacts using contact store iOS9 like so:</p>
  
  <pre><code>private func allContacts() -&gt; [CNContact] {
      let contactStore = AppDelegate.getAppDelegate().contactStore
      let keysToFetch = [
          CNContactFormatter.descriptorForRequiredKeysForStyle(.FullName),
          CNContactPhoneNumbersKey,
          CNContactImageDataAvailableKey,
          CNContactThumbnailImageDataKey
      ]
  
      var allContainers: [CNContainer] = []
      do {
          allContainers = try contactStore.containersMatchingPredicate(nil)
      } catch {
          DLog("Error fetching containers")
      }
  
      var results: [CNContact] = []
  
      for container in allContainers {
          let fetchPredicate = CNContact.predicateForContactsInContainerWithIdentifier(container.identifier)
  
          do {
              let containerResults = try contactStore.unifiedContactsMatchingPredicate(fetchPredicate, keysToFetch: keysToFetch)
              results.appendContentsOf(containerResults)
          } catch {
              DLog("Error fetching results for container")
          }
      }
  
      return results
  }
  </code></pre>
  
  <p>For simplicity as step 1: Assume phone contacts phone numbers are stored exactly like the database format.</p>
  
  <p>Now I would like to check if the contacts on the phone exist in the database. The database could potentially have millions of users stored as above, with the phone number as being the key.</p>
  
  <p>Do I query each number in the phone against the db? If so, can you give a query example please? Json database is new to me and I just can't figure out even how to query one by one.</p>
  
  <p>For step 2: the digits stored in CNContact might have country code in the beginning and might not have it. The country code could be +1 or could be +anything. If the phone has 8585555555 and the db has +1858555555 how to write the query now?</p>
  
  <p>Any help in the right direction is appreciated.</p>
  
  <p>Thanks in advance,</p>