Reputation: 4978
I have my server in nodejs and client in angularjs, mongodb(mongoose) as database. I want my client to be able to make a search query with all the normal consitions put in like fixing few fields to certain values, search string contained in few of the fields etc
query can be
(value of field A can be 'x' or 'y') and
(value of field B can range between dates P and Q) and
(string s contained in fields C or D or E) few more
is there any npm plugin or standardisation I can follow to enrich my server side API and also directly put the expression while querying with out doing a map reduce with multiple queries(with lots of code).
Upvotes: 0
Views: 1174
Reputation: 11285
Yes, there are a few. I only know of those that work with Mongoose so if you're using another driver you may need to modify them a bit.
With each of these you'll need to determine which to filter locally and which to let the server handle it. Where you filter should depend largely on how much data you have. Personally, it made more sense to abandon local filtering for my largest sets and simply rely on MongoDB to handle the workload.
Connecting Mongoose and Angular and More
The original motive for Angoose project is to do away with the dual model declarations(server and client side) if we are building a rich model based SPA application using modern Javascript framework such as Angular and node.js. With both front end and backend using Javascript, Angoose allows the server side models and services to be used in the client side as if they reside in the client side.
Angoose depends on following frameworks and assumes you have basic familarities with them:
- mongoose
- express
- angular (optional, for non-angular app, jQuery is required)
Mongoose plugin that takes a set of URL params and constructs a query for use in a search API. Also, worst project name ever.
If you use Mongoose to help serve results for API calls, you might be used to handling calls like:
/monsters?color=purple&eats_humans=true
mongoose-api-query handles some of that busywork for you. Pass in a vanilla object (e.g. req.query) and query conditions will be cast to their appropriate types according to your Mongoose schema. For example, if you have a boolean defined in your schema, we'll convert the eats_humans=true to a boolean for searching.
It also adds a ton of additional search operators, like less than, greater than, not equal, near (for geosearch), in, and all. You can find a full list below.
When searching strings, by default it does a partial, case-insensitive match. (Which is not the default in MongoDB.)
Link models easily via a REST interface between Mongoose/Node-Express/Angular.js
Create, read, update, delete MongoDB collections via AngularJS.
It uses :
- Mongoose for accessing to Mongodb
- Express for the routing
- AngularJS (with the $resource method)
Upvotes: 1