2.0.0 • Published 8 years ago

dynamic_mongoose_searcher v2.0.0

Weekly downloads
19
License
-
Repository
-
Last release
8 years ago

simplify create mongoose search query with dynamic searching properties and sorting options by passing the searching terms in the http body request using express and body-parser

Installation

$ npm install dynamic_mongoose_searcher

$ Backend

var mongoose = require("mongoose");

var ads_collections = mongoose.model("ads");

var dynamic_mongoose_saerch = require("dynamic_mongoose_search");

exports.search = function (http_request, http_response) {
       var option = {
            'page_number': http_request.params.page_number,
            'limit': 20
        };

        dynamic_mongoose_saerch.create_query(http_request, ads_collections, option, function (error, query) {
            query.populate("city", "name _id");
            query.exec(function (finding_error, result) {
                return http_response.status(200).send(result);
            });
        });
};

$ FontEnd

   http_request body,  search one field

    {
       "city": "5709606579e756e8c1939c7d",  <-- filter using city.id
       
       "sort_options":[{  <--- if you want to sort result
        "sort_field":"create_date", 
        "sort_type": "-1"
        }] 
    }

    http_request body, search multi field with sorting

    {
       "city": "5709606579e756e8c1939c7d",  <-- filter using city.id
       "user": "5709606579e756e8c1939343",  <-- and the user id
       "sort_options":
        [{  
            "sort_field":"create_date", <--- if you want to sort result
            "sort_type": "-1"
        }] 
    }

   http_request body, search multi field without sorting

    {
       "city": "5709606579e756e8c1939c7d",  <-- filter using city.id
       "user": "5709606579e756e8c1939343"   <-- filter using user.id
    }
2.0.0

8 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.0.0

8 years ago