Technology moves fast! ⚡ Don't get left behind.🚶 Subscribe to our mailing list to keep up with latest and greatest in open source projects! 🏆


Subscribe to our mailing list

mongo-query

mongo query API component

Subscribe to updates I use mongo-query


Statistics on mongo-query

Number of watchers on Github 62
Number of open issues 10
Average time to close an issue 20 days
Main language JavaScript
Average time to merge a PR about 5 hours
Open pull requests 1+
Closed pull requests 6+
Last commit almost 4 years ago
Repo Created over 6 years ago
Repo Last Updated about 1 year ago
Size 534 KB
Organization / Authorautomattic
Contributors7
Page Updated
Do you use mongo-query? Leave a review!
View open issues (10)
View mongo-query activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating mongo-query for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

mongo-query

Component that implements the complete MongoDB query JSON API to operate on individual documents.

Example

var query = require('mongo-query');

// our sample document
var obj = {
  name: 'Tobi',
  age: 8,
  location: { country: 'Canada', zip: 123 },
  likes: [{ id: 1, name: 'Food' }, { id: 2, name: 'Stuff' }]
};

// run an operation and get changes
var changes = query(obj, { $set: { 'location.country': 'US' } });

Features

  • Transactional. If an op fails, the others are rolled back.
  • Precise modification logs. Ops return an array of change objects.
    • Noops are excluded.
    • Before/after values are provided.
    • Whether the op triggered the creation of a new array.
  • Error messages almost exactly match MongoDB's.
  • Query support. Allows for support of the positional operator.
  • Wide test coverage.

API

query(obj, filter, modifier, opts)

  • Executes the modifier on obj provided they match filter.
  • Returns an array of change objects (see below). If the modifier does not alter the object the array will be empty.
  • Options:
    • strict if true, only modifies if filter has a match (false).

query.filter(query)

Returns a Query object to perform tests on.

Example: query.filter({ a: { $gt: 3 } }).test({ a: 1 }). For the complete filter API refer to filtr.

query.get(obj, key)

Gets the key from the given obj, which can use dot notation.

Example: query.get(obj, 'some.key').

query.set(obj, key, val)

Sets the key on obj with the given val. Key can use dot notation.

change

All change objects contain:

  • key: the key that was affected. If the positional operator was used, the key is rewritten with dot notation (eg: comments.3.date).
  • op: the type of operation that was performed

Depending on the type of operation they can contain extra fields.

$set

  • value that we set

$inc

  • value value that we increment by

$pop

  • value value that was popped
  • shift if true, it was a shift instead of a pop

$rename

  • value new name

$push

  • value value that was pushed

$pushAll

  • value array of values that were pushed

$pull

  • value array of values that were pulled

$pullAll

  • value array of values that were pulled

$unset

  • value (undefined)

$addToSet

  • value array of values that were added
mongo-query open issues Ask a question     (View All Issues)
  • over 2 years Odd test - odd behavior
  • over 2 years { $exists: false ] FAILS
  • over 3 years Comment: mongo query parser
  • over 6 years Added missing op `$size`
  • over 6 years Add option to return an array of transactions.
  • over 6 years Add $regexp custom $options support
  • over 6 years Support for $and, $or and $nor
  • over 6 years Changes without modifiers
  • over 6 years Operation conflict detection
mongo-query open pull requests (View All Pulls)
  • Fix `filter` example
mongo-query questions on Stackoverflow (View All Questions)
  • Order_by mongo query with multiple model fields
  • How to Mongo query for only fields entered in Search Form?
  • How to convert mongo query to java code
  • Why is Mongo query and Java Mongo Driver query giving me very different results?
  • Meteor: how to get the variable content as key for Mongo query
  • Mongo Query - Number of Constraints vs Speed (and Indexing!)
  • Mongo Query with $in array in Java
  • Mongo query with regex fails when backslash\newline is there in a field
  • Spring Data Mongo Query using method name
  • Laravel Mongodb Raw mongo query with date
  • mongo query for multiple condition
  • Mongo Query Performance
  • Mongo Query Parser Regex
  • Composition in mongo query (SQL sub query equivalent)
  • Mongo query for nested object inside another nested object
  • How to emit returned mongo query with socket.io
  • How to assign the value of a field to another in a single mongo Query
  • Spring Data Mongo Query Field parameters
  • Redirect output of mongo query to a csv file
  • Node app crashing again and again due to mongo query
  • Mongo query condition using IN?
  • Mongo query to check whether today's date is between 2 others
  • what should be the mongo query for this
  • Mongo query for comparing two indexed fields
  • Spring Batch issue with sorting Mongo Query
  • Date Range Mongo Query using Meteor Js
  • Javascript regex with optional capture groups - matching a mongo query
  • Mongo query that matches field to any element of array
  • Mongo query that returns unique data in date range
  • How to unit test grails service method which uses mongo query?
mongo-query list of languages used
Other projects in JavaScript