404 questions
Advice
0
votes
2
replies
38
views
Avoid creating MongoDB collection automatically when using createIndex
In MongoDB 7.0 when I run db.getCollection("NoSuchCollection").createIndex({ Whatever: 1 }); and the collection "NoSuchCollection" does not exist it is automatically created (and ...
1
vote
1
answer
61
views
In a MongoDB transaction, are index entries updated immediately when an indexed field is modified?
I'm working with MongoDB transactions (Node.js, replica set). Inside a transaction, I update a document in a way that changes the value of a field that is covered by an index. Later in the same ...
0
votes
2
answers
77
views
Can a partial multikey index in MongoDB index only certain subdocuments of an array?
I have a MongoDB collection with documents containing an array of subdocuments. For example:
{
"_id": 1,
"addresses": [
{ "city": "New York", "...
1
vote
2
answers
76
views
Mongodb/atlas search with punctuation signals
I am a new developer working with MongoDb Atlas, I am currently working on text searches over a collection with news texts. In this phase I am building the pipelines for those searches, so working ...
-2
votes
1
answer
98
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
102
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
95
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
75
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
58
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
85
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
78
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 }
}
}
])
...
0
votes
1
answer
260
views
How to force MongoDB to always use specific indexes with $or clauses in
I have a MongoDB collection items with the following indexes:
db.items.createIndexes([{ team: 1, a: 1 }, { team: 1, b: 1 }])
I inserted some test data like this:
db.items.insertMany([
{ team: 1, a: &...
0
votes
1
answer
63
views
MongoDB partial index optimization
I have a MongoDB collection and the following query:
{
isActive: true,
managerId: null,
clientId: { $ne: null }
}
I would like to optimize this query by creating an index. It looks like partial ...
0
votes
0
answers
70
views
Using SQL LIKE operator in MongoDB indexes
I have a Flask app that queries my self-managed MongoDB.
I've created an index on two fields so that I can perform a text search on it.
The search is working fine, but it is only matching full words.
...
-1
votes
1
answer
84
views
can a TTL index delete a document currently locked inside a long running transaction?
A TTL index is applied to a mongodb collection. It is instructed to delete documents after expiration if A = true.
A document of this collection is currently locked inside a long running transaction. ...
0
votes
0
answers
38
views
Index not getting applied while $lookup for one of my query but for others it's getting applied. Not able to find out the mistake i am doing
Index not getting applied while $lookup (Customers lookup in my query, _id index is not getting applied) for one of my query but for other query it’s getting applied.
Below is the plan details which ...
0
votes
1
answer
75
views
Difference in creating indexes in mongo db
I would like to know if there is a difference between these two types of index
My goal is to create a composite index in the search for these two keys
collection.Indexes.CreateOne(
new ...
-2
votes
2
answers
191
views
Performance or index usage of the queries on an optional key in MongoDB
When an optional key in a collection is queried , performance varied with respect to the following two queries.
Good response : When it queried with a specific value - a value other than null, it ...
2
votes
0
answers
43
views
Why does this meteor publication go slower when using limit?
I just "solved" a major performance issue in a Meteor.js application I maintain, but what I did seems completely counter intuitive. My guess is that my confusion has to do with my lack of ...
0
votes
0
answers
37
views
How to apply a constraint on data fiedlds in mongodb?
Suppose I have a timeseries mongodb collections, similar to the one proposed in the official website, with a structure that might look like:
[
{
"timestamp": 1,
"...
0
votes
1
answer
230
views
mongodb query not utilising index with $expr
I have an index on the createdAt date field.
I have an aggregation with this $match stage as the first stage:
{
"$expr" : {
"$gte" : [
"$createdAt&...
0
votes
2
answers
176
views
how to get mongodb to use a compound index where one of the fields is not involved?
compound index:
{
A: 1,
B: 1,
C: 1
}
query:
col.aggregate([
{
$match: {
B: "ssome_value",
C: "some_other_value,
}
}
])
The query does not involve A, so the ...
0
votes
1
answer
48
views
compound index and sort query involving a regex
please read comment and first answer. question is solved.
https://mongoplayground.net/p/J1Hs5RKu39G
I need help interpreting the explain output. I can see that the index is used. However, I am still ...
3
votes
0
answers
65
views
will each condition inside an $or of the $match stage be checked concurrently?
compound index
{
A: 1,
timestamp: 1,
}
and
{
B: 1,
timestamp: 1,
}
db.user.aggregate([
{ $match: {
$or: [ { A: "some_value" }, { B: "some_value" } ]
} },
{
...
-1
votes
1
answer
99
views
will mongodb use index to sort when $or used in $match?
compound index
{
A: 1,
timestamp: 1,
}
and
{
B: 1,
timestamp: 1,
}
db.user.aggregate([
{ $match: {
$or: [ { A: "some_value" }, { B: "some_value" } ]
} },
{
...
0
votes
0
answers
24
views
What should I do when I get the excessive memory usage error when sorting in mongodb when I already have indexes created for the field in question?
The following error: "The sort operation used more than the maximum 33554432 bytes of RAM."
I have a find() that returns more than 9,000 records and I need to sort them by a nested field ...
-1
votes
2
answers
117
views
mongodb not using index unless field is specified in $match
compound index
{
A: 1,
B: 1
}
In this query, the compound index is not used:
db.user.aggregate([
{ $match: {
B: { $gt: 100 }
} },
{
$sort: {
A: 1
}
},
{
$limit: ...
0
votes
1
answer
377
views
ESR rule for mongoDB: What if I want to sort on my range index?
I am planning to include indexes to make my mongodb queries faster, currently working on Springboot.
I have variables userType and creationStamp (date and time in epoch milli while saving the document ...
0
votes
0
answers
49
views
MongoDB unique compound index on _id and nested field not working
I have a document with the following structure
{
"_id": 1,
"list":[
{
"_id": {
"$oid": "64e4e7dcb7affd390938c40c"
},
...
0
votes
1
answer
608
views
Is a Time To Live (TTL) index costly?
I am deciding whether to auto delete expired documents via the TTL index or to have a background process that checks every 24 hours.
I have read that the TTL index will check every x milliseconds, etc....
-1
votes
1
answer
79
views
$limit in a scatter and gather query to a sharded collection
user.aggregate([
{
$match: {
age: { $gt: 18 },
city: { $in: ["chicago", "paris"] }
}
},
{
$sort: {
last_logged_in: -1
}
},
{
$limit: ...
0
votes
1
answer
48
views
will this $sort and $limit query use the index or be a blocking in memory sort?
index:
{
last_logged_in: -1
}
query:
user.aggregate([
{
$match: {
age: { $gt: 18 },
city: { $in: ["chicago", "paris"] }
}
},
{
$sort: {
...
-2
votes
1
answer
45
views
The purpose of sharding in mongoDB [closed]
I have a collection that only holds 10 million documents, totaling 10 gigabytes. This may not seem like enough to necessitate sharding.
But there is a query that takes 1000 seconds to complete on this ...
0
votes
1
answer
452
views
unique index only if field exist
If There is a unique index on a field A, then there cannot be 2 documents where A doesn't exist.
How do I specify that the uniqueness should only be enforced on documents where A actually exists?
1
vote
1
answer
567
views
Multikey indexing, performance drawbacks
Consider a collection of approximately 1 mln. documents having the following schema:
{
_id: ObjectId(),
Title: "",
Description: "",
Scheduling: {
From: ...
1
vote
2
answers
318
views
MongoDB createIndexes() Method - Support for individual Index Options
Does MongoDB createIndexes() method, support specifying individual options for each index set in the script. Something like this below, which is not working by the way.
Ref - https://www.mongodb.com/...
1
vote
2
answers
510
views
MongoDB ESR Index Rule - Range Filter and Sorting
The following statement regarding range filter and sorting and the way the predicates had to be placed is confusing.
"MongoDB cannot do an index sort on the results of a range filter. Place the ...
0
votes
0
answers
86
views
MongoDB collection index size using new array field takes more size than expected
MongoDB collection index size using new array field takes more size than expected.
This is a multikey index with an array field as the preceding index column in a collection which already has ...
1
vote
1
answer
120
views
Is there any way to align the order of data written to Mongo with the index order created by Cygnus?
I am investigating Cygnus for FIWARE Orion historical data persistence.
Since Cygnus 3.0.0, indexes are created according to the data model when writing to MongoDB, but the order of the indexes ...
0
votes
0
answers
54
views
Does mongodb sharded collection's performance deteriorate as the number of shards grow?
At what number of shards do sharded collections begin to have a negative impact on the performances of read queries? Hundreds? Thousands? what is the rule of thumb?
0
votes
2
answers
56
views
How to convert array of subdocuments into array of primary data values returned from a $lookup?
The $lookup stage will return an array of subdocuments. But the only value that I am interested in from the result of the $lookup is the the _id value. So instead of an array of { _id: ObjectId() }, ...
0
votes
0
answers
135
views
How to dynamically reference mongoDB field names?
Schema of collection:
{
field_1: "number",
field_2: "number",
...
}
I have a query that may reference field_n dynamically depending on certain conditions that are not ...
0
votes
1
answer
37
views
How to ensure that $sort push missing values to the bottom regardless of ascending or descending
If I sort based on a column that has missing values, the missing values will be on top if sort is ascending.
How to ensure that missing values always get pushed to the bottom regardless of ascending ...
-1
votes
1
answer
145
views
Is there a significant performance difference between sorting by just one field vs sorting by multiple fields? [duplicate]
Assuming that there is no index, is there a significant performance difference between sorting based on just one field vs multiple fields?
db.movies.aggregate([
{ $sort: { likes: -1 } }
{ $limit: ...
-3
votes
1
answer
153
views
$lookup is super slow despite the from collection being empty
The base collection has 100,000 documents. All of which will be run through a $lookup stage. The collection that will be looked up in is empty.
This query takes 30 seconds.
When I remove the $lookup ...
-1
votes
1
answer
45
views
Ensuring that the $sort stage will only hold the number of documents specified in the $limit stage
Consider the case where $limit comes immediately after $sort:
db.col.aggregate([
{ $match: { } },
{ $sort: { } },
{ $limit: 10 }
])
I would assume that in the query above, the $sort stage would ...
-1
votes
1
answer
45
views
how to $sort by field of subdocument belonging to an array?
Schema:
{
A: [
{ name: "string", age: "integer" },
{ name: "string", age: "integer" },
{ name: "string", age: "integer" },
...
0
votes
0
answers
23
views
sorting based on a field that was not modified - will it use the index?
This is a query of my APP that returns a list of users. After the $match stage, some fields will be modified and a $lookup stage is involved to find and remove blocked users.
However, the distance ...
2
votes
0
answers
44
views
I want to use indexes on joined collection in mongodb
I have two collection named as users and user_data, users is a primary collection and the user_data is a secondary collection. I have perform an aggregate query for retrieving millions of data but ...
-1
votes
0
answers
49
views
Want to use indexes on secondary collection of the mongodb
I have two collections mainCol and joinedCol from which using joins i am fetching around millions of records and the db query is taking excessive time, i want to use indexes on the fields of joined ...