Skip to content
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 - On adding text index to field #6472

Closed
onkar0777 opened this issue May 15, 2018 · 5 comments
Closed

Error: cyclic dependency detected - On adding text index to field #6472

onkar0777 opened this issue May 15, 2018 · 5 comments
Labels
can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity.

Comments

@onkar0777
Copy link

Do you want to request a feature or report a bug? Bug

What is the current behavior? Unable to start server because of the error. Error logs:

/Users/ashish/dictionary/js_server/node_modules/mongoose/lib/utils.js:429
        throw err;
        ^

Error: cyclic dependency detected
    at serializeObject (/Users/ashish/dictionary/js_server/node_modules/bson/lib/bson/parser/serializer.js:331:34)
    at serializeInto (/Users/ashish/dictionary/js_server/node_modules/bson/lib/bson/parser/serializer.js:934:17)
    at serializeObject (/Users/ashish/dictionary/js_server/node_modules/bson/lib/bson/parser/serializer.js:345:18)
    at serializeInto (/Users/ashish/dictionary/js_server/node_modules/bson/lib/bson/parser/serializer.js:934:17)
    at serializeObject (/Users/ashish/dictionary/js_server/node_modules/bson/lib/bson/parser/serializer.js:345:18)
    at serializeInto (/Users/ashish/dictionary/js_server/node_modules/bson/lib/bson/parser/serializer.js:934:17)
    at serializeObject (/Users/ashish/dictionary/js_server/node_modules/bson/lib/bson/parser/serializer.js:345:18)
    at serializeInto (/Users/ashish/dictionary/js_server/node_modules/bson/lib/bson/parser/serializer.js:934:17)
    at serializeObject (/Users/ashish/dictionary/js_server/node_modules/bson/lib/bson/parser/serializer.js:345:18)
    at serializeInto (/Users/ashish/dictionary/js_server/node_modules/bson/lib/bson/parser/serializer.js:934:17)
    at serializeObject (/Users/ashish/dictionary/js_server/node_modules/bson/lib/bson/parser/serializer.js:345:18)
    at serializeInto (/Users/ashish/dictionary/js_server/node_modules/bson/lib/bson/parser/serializer.js:934:17)
    at serializeObject (/Users/ashish/dictionary/js_server/node_modules/bson/lib/bson/parser/serializer.js:345:18)
    at serializeInto (/Users/ashish/dictionary/js_server/node_modules/bson/lib/bson/parser/serializer.js:934:17)
    at serializeObject (/Users/ashish/dictionary/js_server/node_modules/bson/lib/bson/parser/serializer.js:345:18)
    at serializeInto (/Users/ashish/dictionary/js_server/node_modules/bson/lib/bson/parser/serializer.js:934:17)
Emitted 'error' event at:
    at done (/Users/ashish/dictionary/js_server/node_modules/mongoose/lib/model.js:1051:13)
    at /Users/ashish/dictionary/js_server/node_modules/mongoose/lib/model.js:1093:16
    at /Users/ashish/dictionary/js_server/node_modules/mongoose/lib/utils.js:424:16
    at err (/Users/ashish/dictionary/js_server/node_modules/mongodb/lib/utils.js:415:14)
    at session.endSession (/Users/ashish/dictionary/js_server/node_modules/mongodb/lib/utils.js:399:27)
    at ClientSession.endSession (/Users/ashish/dictionary/js_server/node_modules/mongodb-core/lib/sessions.js:72:41)
    at executeCallback (/Users/ashish/dictionary/js_server/node_modules/mongodb/lib/utils.js:397:17)
    at err (/Users/ashish/dictionary/js_server/node_modules/mongodb/lib/utils.js:415:14)
    at executeCallback (/Users/ashish/dictionary/js_server/node_modules/mongodb/lib/utils.js:404:25)
    at err (/Users/ashish/dictionary/js_server/node_modules/mongodb/lib/utils.js:415:14)
    at executeCallback (/Users/ashish/dictionary/js_server/node_modules/mongodb/lib/utils.js:404:25)
    at handleCallback (/Users/ashish/dictionary/js_server/node_modules/mongodb/lib/utils.js:128:55)
    at /Users/ashish/dictionary/js_server/node_modules/mongodb/lib/db.js:1068:25
    at executeWrite (/Users/ashish/dictionary/js_server/node_modules/mongodb-core/lib/wireprotocol/3_2_support.js:82:5)
    at WireProtocol.insert (/Users/ashish/dictionary/js_server/node_modules/mongodb-core/lib/wireprotocol/3_2_support.js:91:3)
    at Server.insert (/Users/ashish/dictionary/js_server/node_modules/mongodb-core/lib/topologies/server.js:752:35)

If the current behavior is a bug, please provide the steps to reproduce.

Creating a text index on my field gives this error. Code:

WordSchema = new Schema({
  title: {
    type: String,
    required: true,
  },
  meanings: [MeaningSchema],
  keys: [String],
  tags: [String],
  language: String,
  createdAt: Date,
  updatedAt: Date
});

WordSchema.index({title: 'text'}); ---> Error
WordSchema.index({title: 1});      ---> Works fine

What is the expected behavior?
Should work without errors

Please mention your node.js, mongoose and MongoDB version.
node - 9.11.1
mongoose - 5.1.1 (same with 5.0.8)
MongoDB - 3.6.2

@lineus
Copy link
Collaborator

lineus commented May 16, 2018

@onkar0777 I tried to reproduce your issue with the following code:

6472.js

#!/usr/bin/env node
'use strict';

const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');
const conn = mongoose.connection;
const Schema = mongoose.Schema;

const meaningSchema = new Schema({
  x: String
});

const wordSchema = new Schema({
  title: {
    type: String,
    required: true,
  },
  meanings: [meaningSchema],
  keys: [String],
  tags: [String],
  language: String,
  createdAt: Date,
  updatedAt: Date
});

wordSchema.index({ title: 'text' });

const Test = mongoose.model('test', wordSchema);

const test = new Test({
  title: 'Hello'
});

async function run() {
  await conn.dropDatabase();
  await Test.ensureIndexes();
  await test.save();
  let found = await Test.findOne({ $text: { $search: 'Hello' } });
  console.log(found);
  return conn.close();
}

run();

Output:

issues: ./6472.js
{ keys: [],
  tags: [],
  _id: 5afbf1f76f48d7b762c3ff14,
  title: 'Hello',
  meanings: [],
  __v: 0 }
issues:

This doesn't cause any errors for me. Can you either create a complete example or modify mine to mirror yours to reproduce the error?

@lineus lineus added the can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity. label May 16, 2018
@AugustBrenner
Copy link

I am experiencing this as well. Many large models, when I comment out the ones with text indexes it works, if I comment any of them back in I get a cyclic dependency detected error. Running mongoose 5.1.1, but still have the problem back to 5.0

@AugustBrenner
Copy link

when I comment out the text parts of this index as well as the weights it works.

`Hello.index(
{
'_search_hello_1' : 1,
'_search_hello_2' : 'text',
'_search_hello_3' : 'text',
'_search_hello_4' : 1,
},
{
weights : {
"_search_hello_2" : 5,
"_search_hello_3" : 1,
},

    name 						: 'hello_v1_text_index'
}

)`

also the error exists when I comment out the index: true of the following:

_id : { type : String, required : true, index : true },

@lineus
Copy link
Collaborator

lineus commented May 23, 2018

@onkar0777 @AugustBrenner can you check out #6109, are you by chance using the retryWrites option on your connection?

@vkarpov15
Copy link
Collaborator

Should be fixed by #6109

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can't reproduce Mongoose devs have been unable to reproduce this issue. Close after 14 days of inactivity.
Projects
None yet
Development

No branches or pull requests

4 participants