Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here


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 over 4 years ago
Repo Created about 7 years ago
Repo Last Updated almost 2 years ago
Size 534 KB
Organization / Authorautomattic
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 (?)


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


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: { '': 'US' } });


  • 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.


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).


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.


All change objects contain:

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

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


  • value that we set


  • value value that we increment by


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


  • value new name


  • value value that was pushed


  • value array of values that were pushed


  • value array of values that were pulled


  • value array of values that were pulled


  • value (undefined)


  • value array of values that were added
mongo-query open issues Ask a question     (View All Issues)
  • about 3 years Odd test - odd behavior
  • about 3 years { $exists: false ] FAILS
  • over 4 years Comment: mongo query parser
  • about 7 years Added missing op `$size`
  • about 7 years Add option to return an array of transactions.
  • about 7 years Add $regexp custom $options support
  • about 7 years Support for $and, $or and $nor
  • about 7 years Changes without modifiers
  • about 7 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
  • 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