Darshan Hiranandani : How can I retrieve information on documents that were inserted within the last 2 or 3 days on a standalone server?

Hi Team,

I am Darshan Hiranandani, need to check all documents inserted within a specific time interval on a standalone MongoDB Atlas server. Here’s what I’m looking to understand:

  1. Retrieving Inserted Documents: How can I retrieve details of all documents inserted in a specific time frame across all collections in a MongoDB Atlas database, given that it’s a standalone server?
  2. Using oplog.rs: I’m aware that oplog.rs is used for replicated nodes. Can it be utilized in any way on a standalone server, or is there an equivalent method for standalone setups?
  3. Time-Based Queries: What are the best practices or queries for finding documents inserted within a specific time interval, regardless of the number of collections?
  4. Alternative Methods: Are there alternative methods or tools to track and retrieve documents inserted during a specific period on a MongoDB Atlas standalone server?

Any guidance or suggestions on how to achieve this would be greatly appreciated!

Thanks,

Darshan Hiranandani

If using server generated IDs you can generate an artificial ObjectID to cover the range that you want to filter on. We’ve actually done this recently when we needed to extract data on a day to day basis.

Something like this:

  • Get start and end dates
  • Convert each date to a unix timestamp and then to base 16, padded to 24 chars with trailing “0”
  • In the query compare the _id field against the generated object IDs

This obviously depends on you using default IDs for timestamps, needing to scan each collection (but this should be a fast check). Long term is also locks you into using _id as ObjectID and that Mongo do not change the ordering of the field which should hopefully not happen anyway.

You can use replication log on a single node instance, just setup it up as a replicaset with one node, of source there are limits you can set and update to determine the window of operations that are available.
You could always make use of a change stream at a database level or something to track documents created / day with the _id and date but if using ObjectIDs you’d be basically duplicating data.

Now updated documents…that would be different!