https://github.com/airamrguez/mqf
Filter javascript plain objects. Useful for Mongo queries.
https://github.com/airamrguez/mqf
filter mongodb query select
Last synced: 5 months ago
JSON representation
Filter javascript plain objects. Useful for Mongo queries.
- Host: GitHub
- URL: https://github.com/airamrguez/mqf
- Owner: airamrguez
- License: mit
- Created: 2017-06-15T17:56:07.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-16T15:23:22.000Z (about 9 years ago)
- Last Synced: 2025-08-31T00:15:39.621Z (10 months ago)
- Topics: filter, mongodb, query, select
- Language: JavaScript
- Size: 24.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mqf
> Like classNames for React but for MongoDB queries or whatever you want.
[](https://badge.fury.io/js/mqf)
[](https://travis-ci.org/airamrguez/mqf)
[](https://coveralls.io/github/airamrguez/mqf?branch=master)
## Usage
**Note:** mqf creates a new object with the filtered query.
```js
mqf(
{ a: 3 },
[{ b: 5 }, !isNaN(3)],
[{ c: 3 }, false]
);
// Output
// {
// a: 3,
// b: 5
// }
```
## MongoDB use case
Only admins or post author's can update a post.
```js
db
.collection('posts')
.filterAndUpdate(
mqf(
{ _id: ObjectId(postId) },
[{ authorId: ObjectId(currentUser._id) }, !isAdmin(currentUser)]
)
).
then(result => ...);
```
## License
MIT © [Airam Rguez](https://github.com/airamrguez)