-
Type: Task
-
Resolution: Works as Designed
-
Priority: Minor - P4
-
None
-
Affects Version/s: 2.2.18
-
Component/s: MongoDB 3.2
-
Empty show more show less
Error: cyclic dependency detected
at serializeObject (/project/test/node_modules/bson/lib/bson/parser/serializer.js:296:33)
at serializeInto (/project/test/node_modules/bson/lib/bson/parser/serializer.js:776:17)
at serializeObject (/project/test/node_modules/bson/lib/bson/parser/serializer.js:308:18)
at serializeInto (/project/test/node_modules/bson/lib/bson/parser/serializer.js:776:17)
at serializeObject (/project/test/node_modules/bson/lib/bson/parser/serializer.js:308:18)
at serializeInto (/project/test/node_modules/bson/lib/bson/parser/serializer.js:776:17)
at serializeObject (/project/test/node_modules/bson/lib/bson/parser/serializer.js:308:18)
at serializeInto (/project/test/node_modules/bson/lib/bson/parser/serializer.js:776:17)
at serializeObject (/project/test/node_modules/bson/lib/bson/parser/serializer.js:308:18)
at serializeInto (/project/test/node_modules/bson/lib/bson/parser/serializer.js:776:17)
at serializeObject (/project/test/node_modules/bson/lib/bson/parser/serializer.js:308:18)
at serializeInto (/project/test/node_modules/bson/lib/bson/parser/serializer.js:618:17)
at serializeObject (/project/test/node_modules/bson/lib/bson/parser/serializer.js:308:18)
at serializeInto (/project/test/node_modules/bson/lib/bson/parser/serializer.js:776:17)
at BSON.serialize (/project/test/node_modules/bson/lib/bson/bson.js:58:27)
at Query.toBin (/project/test/node_modules/mongodb-core/lib/connection/commands.js:140:25)
at Pool.write (/project/test/node_modules/mongodb-core/lib/connection/pool.js:921:23)
at Server.command (/project/test/node_modules/mongodb-core/lib/topologies/server.js:515:15)
at Server.command (/project/test/node_modules/mongodb/lib/server.js:376:17)
at executeCommand (/project/test/node_modules/mongodb/lib/db.js:310:19)
at Db.command (/project/test/node_modules/mongodb/lib/db.js:334:44)
at Collection.aggregate (/project/test/node_modules/mongodb/lib/collection.js:2686:13)
Code to reproduce:
const mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
const
= mongoose;
const connect = () => {
const options =
;
mongoose.connect('mongodb://localhost:27017/mongoose_test', options);
};
connect();
mongoose.connection.on('error', (err) =>
{ console.error(err); });
const UserSchema = new Schema({
location: {
type:
,
coordinates:
}
});
UserSchema.index(
);
const User = mongoose.model('User', UserSchema);
const userId = '586d3620f6da431b4aec1a12';
let user = new User(
{ _id: userId })
user.save();
function getUserLocation() {
return User.findById(userId)
.then((user) => {
return new Promise((resolve, reject) => {
if (user && user.location)
else
{ reject(); } });
});
}
function myAwesomeFunction(userLocation) {
return User.aggregate([{
$geoNear:
}
]);
}
getUserLocation()
.then(myAwesomeFunction)
.then(console.log)
.catch(console.error);