12,642 questions
Best practices
0 votes
1 replies
54 views
Mongodb Using aggregates for advanced search
Trying to solve a conundrum I have in writing some queries. I’ve traditionally used simple find operations (and cursor operations for paging functionalities), but need something more complex to ...
0 votes
1 answer
115 views
Randomly slow MongoDB queries
I have been experiencing slow mongo queries suddenly. The execution times varies very randomly. Initially I was suspecting this expensive aggregation operation :- { "appName": "XXXXXX&...
0 votes
1 answer
59 views
mongo aggregate `$in` behaves differentyl than the `$in` in a query filter?
i tried to count stuff in group (by a filed location) but with a condition. So i got a group with multiple values: escalated and non-escalated. (and count for testing) The condition is a boolean field ...
0 votes
1 answer
65 views
MongoDB Aggregation $text search fails with none existing collection in the error returned in Node.js
I'm encountering a very strange issue after switching a MongoDB aggregation pipeline from using $regex to a more efficient $text search. My application code is correct, but the server returns an error ...
-2 votes
1 answer
95 views
In MongoDB, is there a performance difference between $in covering all possible values vs leaving the field out in a compound index?
I’m working with a MongoDB compound index like this: db.users.createIndex({ gender: 1, city: 1, age: 1 }) Suppose city has only a few possible values, e.g., "Chicago", "LA", "...
-3 votes
1 answer
97 views
query that tries to match everything does not use the index [closed]
https://mongoplayground.net/p/2CHyeuaG0y0 db.test.aggregate([ { $match: { $or: [ { cheese: { "$exists": true } }, { ...
0 votes
1 answer
91 views
Does MongoDB update an index when array elements are only reordered?
I’m working with a collection where documents contain an array of subdocuments, for example: { "_id": 1, "tasks": [ { "priority": 2, "dueDate": "...
-1 votes
1 answer
71 views
Can MongoDB use a compound index to sort when filtering with $in?
I have a users collection with a compound index: db.users.createIndex({ bin: 1, gender: 1, age: 1, location: 1, // ... other fields }); When I query like this: db.users.find({ bin: X, ...
0 votes
1 answer
55 views
Performance impact of updating leading vs. trailing fields in a MongoDB compound index
I am working with MongoDB and have a compound index on a collection, e.g., { a: 1, b: 1 }. I want to understand the performance implications when updating documents with respect to the fields in this ...
-2 votes
1 answer
83 views
can mongoDB use the full depth of a compound index on an array of subdocuments?
index: { "name": "tar", "key": { "tar.a": 1, "tar.b": 1 } tar is an array of subdocuments. query: ...
-5 votes
1 answer
77 views
Can MongoDB use an index for $exists: false on an indexed field? [closed]
Given a aggregation pipeline like this, in which I use a $match with { $exists: false } on a indexed field: db.collection.aggregate([ { $match: { myField: { $exists: false } } } ]) ...
1 vote
1 answer
82 views
Nested grouping with Doctrine ODM MongoDB aggregation framework
Doctrine ODM allows to group a set of matched documents: https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/2.9/reference/aggregation-stage-reference.html#group Consider documents ...
0 votes
1 answer
60 views
Mongo how to group by and count all values which is in list of dicts
How to group by and count value of field which is in list? I have documents looks like this: [ {"_id": "some_id","uuid": "unique_uuid", "my_field": [{&...
0 votes
0 answers
31 views
Google map matrix limitations in node js
I'm using the Google Maps Distance Matrix API to calculate route-based distances (not straight-line distances). However, since third-party API calls cannot be made within a MongoDB aggregation ...
1 vote
0 answers
26 views
Efficient Pagination with $lookup across Two MongoDB Collections with Filters on Both Sides
I have two MongoDB collections: c1 and c2. c1 has properties: p1, p2 c2 has properties: p3, p4 c1._id is referenced by c2.customerId I need to: Perform a $lookup to join c1 with c2 Apply filters on ...