mongodb :: NativeMongoCollection :: save
# Wrapper for `mongoc_collection_save()`.
#
# This function shall save a document into the collection.
# If the document has an `_id` field it will be updated.
# Otherwise it will be inserted.
#
# You can retrieve a generated `_id` from `sys.last_mongoc_id`.
fun save(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_save(self, document, NULL, &error)) {
NativeMongoCollection_set_mongoc_error(self, &error);
return false;
}
return true;
`}
lib/mongodb/native_mongodb.nit:341,2--361,3