query with date greater not working in mongoDB - mongodb-compass

Object looks like this:
_id:748633163339
lastModifiedDate:2019-06-02 00:57:34.077
My query looks like this:
{"lastModifiedDate": {$gt: ISODate("2022-03-10")} }
I'm looking for all entries after 3/10 2022. I am unable to execute the query in compass. What is wrong with it?

Related

How to query MongoDB with “like” in codeigniter?

I want to query something with SQL's like query:
SELECT * FROM users WHERE name LIKE '%m%'
How to do I achieve the same in MongoDB? I can't find an operation for like in the documentation of codeigniter.
db.users.find({"name": /m/}))
Should be everything you need.

View last N documents using MongoDB Compass

I wish to view in MongoDB Compass the last N documents in a very large collection; too many to scroll through.
I could .skip(total - N) if I knew the syntax for that within Compass.
Alternatively, I have a date field and could use $gte with a date if I knew how to express a date in a manner acceptable to Compass.
Suggestion/example how to do this, please?
MongoDB Compass 1.6.1(Stable)
For date comparison you need to use $date operator with a string that represents a date in ISO-8601 date format.
{"date": {"$gte": {"$date": "2017-03-13T09:51:26.317Z"}}}
In my case the values of date field in Compass and mongo shell are different. So firstly I query the documents in the shell and then copy the "2017-03-13T09:51:26.317Z" from the result to the Compass filter line. In mongo shell it look like:
{
...
"date" : ISODate("2017-03-13T09:51:26.317Z"),
...
}
MongoDB Compass 1.7.0-beta.0 (Beta)
This version have an advanced query bar that lets you input not just the filter (as before), but also project, sort, skip and limit
(#Oleksandr I learned from your effective answer; thank you.)
I've also been shown that the Compass Schema tab allows one to drag a date range on the _id field to apply a filter query for that range. That range can be successively narrowed as desired.
Skip is descibed here
https://docs.mongodb.com/compass/current/query/skip/
In the Query Bar, click Options.
Enter an integer representing the number of documents to skip into the Skip field
Click Find to run the query and view the updated results.

How can I perform like query for big decimal number containing decimal part in it in mongodb

I have perform like query in mongodb. I have following document in employee collection as:
{
"_id" :1
"name":"Abc",
"salary": 56789.98456
}
So far,I have performed like query to match the above employee document. I have tried following queries in mongo:
db.employee.find({"salary":/.*56789.98.*/}).pretty()
db.employee.find({"salary":/^56789.98/}).pretty()
db.employee.find({"salary":/56789.98/}).pretty()
But it doesn't work.
I also looked at:
How to query MongoDB with "like"?
How do I achieve this in mongo ?
You can do something like this:
db.employee.find({"$where":"/^56789.98.*/.test(this.salary)"})

Filtering & sorting by dates in MongoDB's oplog

I'm trying to filter oplog.rs to view operations that were logged after a certain date. But comparison operators don't seem to work with dates in MongoDB:
db['oplog.rs'].find({ts: {$gte: ISODate("2014-12-15T00:00:00Z")}})
What's confusing is a lot of online sources are saying to do it this way but it is obviously not working. I want to return results where the ts field is at least December 15th or more recent, but I am getting results that are clearly before this period. If I switch $gte with $lte no results at all are displayed, even though there are definitely entries both before and after this specified date.
Also, I can't seem to sort the results either. If I try this:
db['oplog.rs'].find().sort({ts: -1})
I get this:
error: {
"$err" : "Runner error: Overflow sort stage buffered data usage of 33566005 bytes exceeds internal limit of 33554432 bytes",
"code" : 17144
}
If I could filter the results to make them more recent, I am hoping it would overcome this sorting error, but I can't even do that with MongoDB's basic operators. How can I filter the results of a find operation by date?
Comparion operators work just fine with date, but ts is a Timestamp object - not a date.
Your query needs to look something like this:
db['oplog.rs'].find({ts: {$gte: Timestamp(ISODate("2014-12-15T00:00:00Z").getTime(),0)}})
This creates a Timestamp object based on an ISODate and uses it in the query.

Meteor JS: Date Range Query in Mongo

I have a collection that contains a dateAcquired attribute (which is from an XML API Feed the app is consuming).
I am trying to write a .find() query that will pull back all of the entries that are greater than or equal to 1 month ago from today.
The dateAcquired field date looks like: "dateAcquired": "2014-03-28 06:08 AM".
How to do that query in mongodb?
As Neil Lunn already stated, you should use timestamps for your dates in mongo.
More information to parse dates and so on are here
If you use timestamps, then you may use something like this as find selector over you mongo collection:
{dateacquired:{$gte: date_from, $lte: date_to}}
You can calculate the dates with momentjs (recommended) or whatever.