insertMany without returning a list of _id's

Hi

I want to use insertMany, but I don’t need the list of inserted _id’s. This will impact, how small ever, the network bandwidth. Is there an alternative bulk insert method that does not return the list?

I’m specifically using mongocxx 3.5.0.

Hi @rompelstompel, welcome!

Depending on your use case, you can set the acknowledge_level to k_unacknowledged. i.e.

auto writeConcern = mongocxx::write_concern{}
writeConcern.acknowledge_level(mongocxx::write_concern::level::k_unacknowledged); 

However, please note that if there are any errors during the insert (one or many documents) it wouldn’t be returned as well which could lead to missing data without you knowing.

I would recommend just to leave it as is, and just discard the returned result from insert_many().

Regards,
Wan.

1 Like