From c1245af8876ddf9ce465ca61dd951d2b33f4095b Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Sat, 9 Apr 2016 14:10:24 -0700 Subject: [PATCH] fix(query): add $geoWithin query casting for single embedded Fix #4044 --- lib/schema/embedded.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/schema/embedded.js b/lib/schema/embedded.js index e882af7b343..ad0f90a8bd0 100644 --- a/lib/schema/embedded.js +++ b/lib/schema/embedded.js @@ -48,6 +48,19 @@ function Embedded(schema, path, options) { Embedded.prototype = Object.create(SchemaType.prototype); +/** + * Special case for when users use a common location schema to represent + * locations for use with $geoWithin. + * https://docs.mongodb.org/manual/reference/operator/query/geoWithin/ + * + * @param {Object} val + * @api private + */ + +Embedded.prototype.$conditionalHandlers.$geoWithin = function(val) { + return { $geometry: this.castForQuery(val.$geometry) }; +}; + /** * Casts contents *