Skip to main content

Posts

partial search with firestore

You can provide partial search [ type ahead facility ] with firestore. It's not that much streight forward and also not feasible in case of large amount of data that has to support the partial search. Here is just a sample of how you provide partial search with firestore. Logic behind the search is a custom kind of indexing that enables partial search for us. You need to create a collection of documents called indexes which contains indexes generated for the fields you want to search over. First reqirement is to create every possible partial search strings. Below function returns array of the possible indexes generate after chopping out input string character by character. /* storing searchabel fields */ function _chopped_object(iString) { var searchables = {} for (i = 0; i < iString.length; i++) { var string_part = iString.substr(0, iString.length - i) searchables[string_part] = true } return searchables } Output of _chopped_o...

Creating nested documents in firestore

Firestore returning no records yet, I see them in console Collection not retuning any element. ... ...  You might facing issues written above. Then it might be this case. You might getting empty response in this kind of query though there are elements in firestore. db.collection(collection1).doc(doc1) .collection(collection2).doc(doc2) .collection(collection3).get() .then( function (querySnapshot) { querySnapshot.forEach( function (doc) { console.log(doc.id, " = " , doc.data()); } ) I face the same problem. Though data was stored sucessfully ( I was guessing, which was wrong actully ) .  To verify that your data is not stored as you expceted you can do check this. Key in italics font means element is deleted If key of your data is in italic font then your data is not stored or is marked as deleted [ that was happening in my case ]. See in image. Now you might thinking, that I have created element and  not del...

Upload Files to Firebase Storage with dropzone.js

Almost every file uploader I found on web are expecting url to where we want to upload file. If you are using firebase storage then you will find this awkward as you don't have any rest url where you have to upload file .  Instead, file upload handled by firestore library firebase-storage. After certain effort I found a way to use dropzone.js with firebase storage. Here is some snippet of code which you may find useful, If you are in the same situation as I am. This both function are in same file Dropzone configuration.. ( in index.js ) var myDropzone = new Dropzone( "form#dropzone" , { // Make the whole body a dropzone url : '/' , addRemoveLinks : true , method : 'put' , chunking : true , forceChunking : true , autoQueue : false , autoProcessQueue : false }); myDropzone.autoDiscover = false ; myDrop...

Firebase - update a spacific fields of single element of object of array in firestore

Firebase - update a spacific fields of single element of object of array in firestore  Its actully advisable to use map instead of array when ever it is possible. But, there are cetain cases where you don't have option to do so.  For example, you are directly saving the response from some outer source without any modification and they send you an array. In this case you will have array to work with. Firestore does not support array here is why  "bad things can happen if you have multiple clients all trying to update or delete array elements at specific indexes. In the past, Cloud Firestore addressed these issues by limiting what you can do with arrays " For more details information you can refer to Kato Richardson post Best Practices: Arrays in Firebase .  Firestore document having array [ used from stackoverflow question ] Suppose you have array of object something like shown in array. Now you want to update endTime field of the object on the inde...

mailgun forward incoming mail

Mailgun is email service provider. For detail infomration about mailgun you can visit its site mailgun.com . Untill my last project( blogger-editor.xyz ) i was just using mailgun sending mails. There was no need to receive emails on that domain. But in blogger-editor.xyz , I need to have a domain based email address on which i should send and receive email. Its quite straight forward setup to receive email through mailgun. Just you have to do these two things : Make sure your mx record points to mailgun. [ It should be ticked verfied on mailgun dns verification ] Setup route on mailgun MX Record setup with Domain Registrar In domain verification and Dns section of mailgun you will find that you have to setup two mx record with your domain service provider. mxb.mailgun.org ( priority 10 ) mxb.mailgun.org ( priority 10 ) During creation of mx record you will be asked for host. Host value for your record is the @ if you are using root domain with mailgun , and it w...

Find count of day differance between two dates

In golang there is no direct way [ atleast i don't know ] to find count of differance in days between two days. So, I do it the way might every one does [ except who has already faced this ]. Partial Solution What I does is just find out duration differance of two dates using sub function. differance := time.Now().Sub( startTime ) daysCount := int(differance.Hours() / 24.0) It might seem ok. But, there is a problem with this solution.  Let assume, startTime is 2018-02-02 23:59:59 .   In this case daysCount will be 0 on next day [ 2018-02-03 ] until time is 2018-02-03 23:59:59. Perfect Solution Simple solution is just normalize startTime to starting of that date . normalizedTime := time.Date(startTime .Year(),startTime .Month(),startTime .Day(), 0, 0, 0, 0, time.Local) differance := time.Now().Sub( normalizedTime ) daysCount := int(differance.Hours() / 24.0) normalizedTime is startTime but at starting of date. So, Now we are subs...

Setup forward proxy in apache2

Proxy word is noramally used for forward proxy. It forwards requst to other server and pass downs the response to the client. This post is not supposed to describe the differneace between forward and revsers proxy.  But if you want to find out exact differance you can refer this stackoverflow post.   https://stackoverflow.com/questions/224664/difference-between-proxy-server-and-reverse-proxy-server To setup forward proxy on your apahce2. you have to install [ if you are on linux ] / enable [ if you are using windows ] modules mod_proxy.so mod_proxy_ajp.so mod_proxy_balancer.so mod_proxy_connect.so mod_proxy_http.so mod_slotmem_shm.so mod_ssl.so [ If I am includeing any extra please corrent me. But I had to eanble all this modules. ] You have to make virtual host for proxy forward < VirtualHost *: XX  > ProxyRequests On ProxyVia On < Proxy * >   Require all granted < /Proxy > </VirtualHost...