I am building an application that requires a transfer of data from MongoDB documents to an SQL Server table. I am creating a JSON file for exporting the MongoDB documents into it (the code for which has been attached herewith). How do I now add a filter such that only the documents created in the MongoDB collection after a specific data re exported to the JSON?
I believe this can be achieved by somehow using the timestamp in the ObjectId field of a MongoDB document, but could not find out how.
using (FileStream fs = File.Create(path))
{
using (var fw = new StreamWriter(fs))
{
fw.Write("[");
using (var cursor = await collection.Find(new BsonDocument()).Project(Builders<BsonDocument>.Projection.Exclude("_id")).ToCursorAsync())
{
while (await cursor.MoveNextAsync())
foreach (var doc in cursor.Current)
{
fw.Write(doc.ToString());
fw.Write(",");
}
fw.Flush();
}
fs.SetLength(fs.Length - 1);
fw.Write("]");
}
}