-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Incorrect Date casting in geoNear queries #5765
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Comments
Will investigate ASAP, thanks for reporting 👍 |
vkarpov15
added
the
needs repro script
Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
label
Oct 30, 2017
yup it does look like in the geoNear queries it does it differently: const mongoose = require('mongoose');
const co = require('co');
mongoose.Promise = global.Promise;
const GITHUB_ISSUE = `gh-5765`;
mongoose.set('debug', true);
exec()
.then(() => {
console.log('successfully ran program');
process.exit(0);
})
.catch(error => {
console.error(`Error: ${error}\n${error.stack}`);
});
function exec() {
return co(function* () {
yield mongoose.connect(`mongodb://localhost:27017/${GITHUB_ISSUE}`, { useMongoClient: true });
const schema = new mongoose.Schema({
coords: {
type: [Number],
index: '2dsphere'
},
imADate: Date
});
const Model = mongoose.model('Model', schema);
yield Model.ensureIndexes();
yield Model.geoNear({
type: 'Point',
coordinates: [-118.24368, 34.05223],
}, {
spherical: true,
maxDistance: 100000,
num: 10,
query: { imADate: { '$gte': new Date().toISOString() } } // queries date with '2017-11-03T02:55:40.644Z'
});
yield Model.find({ imADate: new Date().toISOString() }); // correctly puts `new Date()`
});
} |
sobafuchs
added
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
bug?
needs repro script
Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
labels
Nov 3, 2017
Looks like we did not cast the |
👍 👍 👍 I tried and failed to add this myself :) |
vkarpov15
added a commit
that referenced
this issue
Nov 5, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mongo: 3.4.9 Node: 8.1.2 Mongoose: 4.12.4
In general when you run a query using a date, such as a count, you can write something like
return Foo.count({ imADate: { '$gte': new Date() } })
or using Moment JS:
return Foo.count({ imADate: { '$gte': moment().toISOString() } })
and a few other variations.
Debug output shows something to the effect of:
Mongoose: foos.count({ imADate: { '$gte': new Date("Sat, 28 Oct 2017 03:49:28 GMT") } }, {})
All is well and good.
However in the query field on a geoNear query:
No such casting seems to occur. The result outputs:
The date is not wrapped in a
new Date(
and therefore doesn't work. Is there improper use on my part or is this a bug?The text was updated successfully, but these errors were encountered: