# Wrapper for `mongoc_collection_insert()`.
#
# This function shall insert `document` into the collection.
# If no `_id` element is found in document, then a `bson_oid_t` will be
# generated locally and added to the document.
#
# You can retrieve a generated `_id` from `sys.last_mongoc_id`.
fun insert(document: NativeBSON): Bool import set_mongoc_error, set_mongoc_last_id `{
bson_oid_t oid;
if(!bson_has_field(document, "_id")) {
bson_oid_init (&oid, NULL);
BSON_APPEND_OID (document, "_id", &oid);
NativeMongoCollection_set_mongoc_last_id(self, &oid);
}
bson_error_t error;
if(!mongoc_collection_insert(self, MONGOC_INSERT_NONE, document, NULL, &error)) {
NativeMongoCollection_set_mongoc_error(self, &error);
return false;
}
return true;
`}
lib/mongodb/native_mongodb.nit:319,2--339,3