Hi Jasbir,
To help digging more on this:
Based on the information that you have described, perhaps a new field could be added to your document schema to distinguish between dirty and non-dirty records.
For example, the value of the dirty field could be a last modified date:
{
...
lastModified: ISODate("2015-09-23T04:11:18.965Z")
}
On an update operation, also set the field to mark all the documents updated as ‘dirty’ state.
The following example updates all documents matching status=test
, sets lastModified
field to the current date, and sets example
field to 99.
/* Get a current date */
var newLastModified = new ISODate();
db.collection.update(
{ status: 'test' },
{ $set: {
lastModified: newLastModified,
/* Any fields that you want to update */
example: 99
}
},
{ multi: true }
)
Afterwards, an example to query the records that were not updated :
/* Find the latest updated record */
var updatedDoc = db.collection.findOne({
$query: {},
$fields: { lastModified:1 },
$orderby: { lastModified:-1 }
}
)
/* Find all records that are older than the last batch of updates */
db.collection.find({ lastModified: { $lt: updatedDoc.lastModified } } );
Kind Regards,
Wan.