Automatic field creation for bulk write operations mongodb

Hi i need to do bulk insert with createdon [timestamp] auto field,

at the moment I am manually creating the createdon timestamp and setting it to the document and then calling the insert method. for inserting one document it is ok,

But this is not efficient for doing bulkinsert with missing entries,

Can anyone show how to do bulkInsert data with auto field
or suggest some better solution for creating auto field in mongodb

Actual data for BulkWrite insert:

BulkInsertList:

[
    {
    fieldOne:val,
    fieldTwo:val,
    fieldThree:val,
    fieldFour:val
    },
    {
    fieldOne:val,
    fieldTwo:val,
    fieldThree:val,
    fieldFour:val
    },
    {
    ..
    }
    ..,
]   

      

Bulk record should insert data with generated timestamp,

Expected Result,

BulkInsertList:
[
    {
        fieldOne:val,
        fieldTwo:val,
        fieldThree:val,
        fieldFour:val,

        createdOn: Timestamp
    },
    {
        ..
    },
    {
        ..
    }
]   

      

+3


source to share





All Articles