Mongodb aggregation pipeline how to limit a group push

Suppose the bottom left coordinates and the upper right coordinates are respectively [0, 0] and [100, 100]. From MongoDB 3.2 you can use the $slice operator to return a subset of an array which is what you want. db.collection.aggregate([ { “$match”: { “loc”: { “$geoWithin”: { “$box”: [ [0, 0], [100, 100] ] } }} … Read more

Running MongoDB Compass on Mac

System Preferences >> Security & Privacy >> General >> [Unlock]>> Allow apps Downloaded from >> You will find an alert specifically for MongoDB Compass Previously there was an option to enable from “Anywhere”. Now it’s removed.

Can MongoDB use an index when checking for existence of a field with $exists operator?

Updated: Seems $exists queries use index properly now based on these tickets $exists queries should use index & {$exists: false} will not use index Old Answer: No, there is no way to tell mongodb to use index for exists query. Indexing is completely related to data. Since $exists is only related to the keys (fields) … Read more

$or statement in $elemMatch

Sure it is, just clearing up the syntax but you basically had it: { “opened”: { “$elemMatch”: { “closed”: false, “$or”: [ { “openingEvening”: { “$lte”: currentTime }, “closingEvening”: { “$gte”: currentTime } }, { “openingMorning”: { “$lte”: currentTime }, “closingMorning”: { “$gte”: currentTime } } ] } } } And given a sample idea … Read more

How to do pagination using range queries in MongoDB?

Since the collection I was paging had duplicate values I had to create a compound index on ProductName and id. Create Compound Index db.ProductGuideItem.ensureIndex({ ProductName:1, _id:1}); This solved my problem. Reference: https://groups.google.com/d/msg/mongodb-user/3EZZIRJzW_A/oYH79npKZHkJ Assuming you have these values: {a:1, b:1} {a:2, b:1} {a:2, b:2} {a:2, b:3} {a:3, b:1} So you do this for the range based … Read more

mongoDB query “WHERE _id > threshold”

Compare like with like The _id key in mongo is not (by default) a string – it is a mongo objectId. You need to compare to the same type to get a meaningful result: var ObjectId = require(‘mongodb’).ObjectID; var oid = new ObjectId(); db.things.find(_id: {$gt: oid}); Don’t read mongoexport files Mongo export files look like … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)