Manish Rathod
Manish Rathod

Reputation: 41

Is there any option that returns newly updated or created document with full object instead of count in mongoose bulkWrite() method?

const operations = [
    {
        updateOne: {
            filter: { email: '[email protected]' },
            update: {
                firstName: 'firstName.1',
                lastName: 'lastName.1',
                password: 'Password',
            },
            upsert: true,
        },
    },
    {
        updateOne: {
            filter: { email: '[email protected]' },
            update: {
                firstName: 'firstName.2',
                lastName: 'lastName.2',
                password: 'Password',
            },
            upsert: true,
        },
    },
    {
        updateOne: {
            filter: { email: '[email protected]' },
            update: {
                firstName: 'firstName.3',
                lastName: 'lastName.3',
                password: 'Password',
            },
            upsert: true,
        },
    },
];

I have above operations that I want to perform inside bulkWrite operation.

try {
    const bulkWriteRes = await users.bulkWrite(operations);
    console.log(bulkWriteRes);
} catch (err) {
    console.log(err);
}

But inside bulkWriteRes I;m getting only these details.

BulkWriteResult {
    ok: 1,
    writeErrors: [],
    writeConcernErrors: [],
    insertedIds: [],
    nInserted: 0,
    nUpserted: 1,
    nMatched: 3,
    nModified: 3,
    nRemoved: 0,
    upserted: [
        {
            index: 5,
            _id: '63c977188eb489a9c9cfa4e2',
        },
    ],
};

I want whole updated object whether it is created or update including filed _id, fields that I have passed in filter and update properties. Is there any options ?

Upvotes: 3

Views: 897

Answers (0)

Related Questions