Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ghatul/advance-search
To build boolean(and-or) search query for mongodb
https://github.com/ghatul/advance-search
Last synced: 10 days ago
JSON representation
To build boolean(and-or) search query for mongodb
- Host: GitHub
- URL: https://github.com/ghatul/advance-search
- Owner: ghatul
- Created: 2019-01-04T03:19:09.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-01-06T06:58:07.000Z (almost 6 years ago)
- Last Synced: 2024-11-02T18:51:43.207Z (13 days ago)
- Language: JavaScript
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
Awesome Lists containing this project
README
# Advance search:
![](http://img.shields.io/badge/stability-stable-green.svg?style=flat)
This module help to build advance mongodb search queries.
Like........
EX.
(nodejs ANd php or angullar 4)
(nodejs or (java and (angular 2 or (reactjs and javascript))))
(nodejs and php or (java and php or (mongodb and typescript)))
(sql and (mongodb or (dynamodb oR (redis or dynamodb) or (mongodb and javascript))))# How to use it:
const gk = require('and-or-search');
Example: (Support collection array & string attributes)
1. let res = gk.query('(nodejs AND (java or php))', 'skills', 'array');
2. let res = gk.query('(tom or jon)', 'first_name', 'string');
-> 1st parameter is infix expression.
-> 2nd is the name of collection attribute.
-> 3rd is the type of collection attribute (array or string).Pass the response query to mongodb for search.
let res = gk.query('(nodejs AND (java or php))', 'skills', 'array');
db.collection('user')
.find(res.query)
.then(result => {
//
}).catch(err => {
//
})# Response types:
{ message: "success", code: 200, query: [object] }
{ message: "Please provide expression to evaluate", code: 400, query: {} }# User collection:
{
"_id" : ObjectId("5c30e7c172fbebb2a8776d2c"),
"first_name" : "tom",
"last_name" : "PQR",
"skills" : [
"nodejs",
"php",
"mongodb"
],
"role" : "admin"
}{
"_id" : ObjectId("5c30e82b72fbebb2a8776d45"),
"first_name" : "Jon",
"last_name" : "XYZ",
"skills" : [
"cordova",
"javascript",
"swift"
],
"role" : "admin"
}