New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: cyclic dependency detected #6109
Comments
What was the original issue here? |
Try to include the field which needs to be updated instead of whole object. |
I too have this issue, same line of code. |
@nparsons08 Ping. Can you tell us whether it did turn out to be an issue on your end, you found a workaround (besides downgrading to an earlier mongoose version), or you resolved it in another way? |
Same here and absolutely no way to track down. The Error comes and goes.
|
Currently experiencing the same issue. Any idea how to resolve this. |
Locking this because "Currently experiencing the same issue" is too vague to be actionable. Please open up a new issue and follow the issue template. |
guys, I guess I found the cause - apparently it is related to mongodb 3.6 (I recently upgraded from 3.2 to 3.6 and mongoose got upgraded to 5.x as well)... so I was not being able to run my app anymore, I was getting these cyclic dependency errors... the only work-around that worked for me was to add long story short I managed to fix it by removing all attributes INDEX from inside my models and appending them to the model afterwards, like this: before client: { type: ObjectId, ref: 'tsCli', required: true, index: true }, after client: { type: ObjectId, ref: 'tsCli', required: true },
[...]
Schema.index({ client: 1 }); AND, more importantly, removing attribute INDEX from compound indexes, i.e.: before Schema.index({ client: 1, code: 1 }, { unique: true, index: true, partialFilterExpression: { code: { $type: String } } }); after Schema.index({ client: 1, code: 1 }, { unique: true, partialFilterExpression: { code: { $type: String } } }); hope this helps others |
I'm specifically encountering this issue when attempting to add index on an array: ...
tags: {
type: [String],
index: true
}
... Simply adding that prop/index to my schema is causing this issue |
hey @AndrewBarba .. try adding the index like I mentioned, not on the field but on the schema and see if it works |
@gustvao I actually tried that first, no luck :( |
@AndrewBarba I had this same issue. Using MongoClient I had to use : Collection.createIndexes([
{
key: { email: 1 },
name: 'user_email',
unique: true
}
]) Hope this helps. |
Happens to me when trying to add a text index:
Creating a text index on my field gives this error. Code:
node - 9.11.1 |
Might be worth noting, I was using the
Once I removed the uri options the issue went away without any other code changes:
|
Can confirm - removing |
Hi @vkarpov15, What is the impact of removing retryWrites for Atlas, is this something that mongoose is doing internally? I open this issue about retryWrites Regards, |
Hi Error: cyclic dependency detected |
Will investigate and check whether turning on |
I can confirm that removing |
Confirmed! removing |
Works on Atlas: MongoDB cluster without |
For me, I ran into this issue when having In mongo shell, executing Then I downgraded the After ensuring that the index had been successfully created, I upgraded the |
Found the issue. It has nothing to do with Atlas, or const mongoose = require('mongoose');
mongoose.set('debug', true);
Error.stackTraceLimit = Infinity;
const { Schema } = mongoose;
run().then(() => console.log('done')).catch(error => console.error(error.stack));
async function run() {
await mongoose.connect('mongodb://localhost:27017/test', {dbName: 'test'});
const M = mongoose.model('Test', new Schema({ _id: { type: String, index: true } }));
await M.create({ _id: 'abc' + Math.random() });
console.log(await M.findOne());
} Will open up a PR in the mongodb driver for this |
nice @vkarpov15 |
I fixed mine by removing retryWrites querystring from the connection string . before after hope this helps. |
Try removing any indexes you have on |
@vkarpov15 I think there may be two issues here. I don't have any indexes on |
@vkarpov15 Here is a script that produces this issue without any index on Mongoose: v5.1.5 const mongoose = require('mongoose')
const { Schema } = mongoose
async function run() {
try {
await mongoose.connect('mongodb://localhost:27017/test?retryWrites=true', {
dbName: 'mongoose-issue-6109'
})
const Model = mongoose.model('Model', new Schema({
email: {
type: String,
index: {
unique: true
}
}
}))
await Model.create({
email: 'mongoose@test.com'
})
console.log(await Model.findOne())
} catch(err) {
console.error(err)
}
}
run() |
Setting an index field to:
Also always triggers this issue |
Yeah, this seems to be a legit issue - I've scanned my codebase for bad indexes and it still seems to reoccur. Downgraded to Links to #6469 - a few more repro steps. |
I've seen the bug. email: { credentialSchema.index({ email: 1, domain: 1, ipAddress: 1, password: -1 }); i had to remove unique from the model definition. |
@AndrewBarba thanks for the repro, I found another issue like node-mongodb-native#1740, see mongodb/node-mongodb-native#1758 . This fix will end up in mongoose once a new version of the mongodb driver is released. |
I encountered the same issue when using atlas, but everything was fine locally. A quick fix around it, as someone suggested is removing the parameter |
Should be fixed in 5.1.8 |
I got some issue with MongoDB Atlas and GridStore, write operation was not working until i removed "retryWrites=true". |
Running the latest version of Node.js on macOS. Also running the latest version of Mongoose.
Seeing
Error: cyclic dependency detected
with literally no way to debug. Everything points back to Mongoose. Any suggestions? Started happening today.The text was updated successfully, but these errors were encountered: