Open cwiese opened 9 years ago
does this even come close?
insert_bulk( collection::MongoCollection, documents::Vector{Mongo.BSONObject}, flags::Int = MongoInsertFlags.None ) = begin
bsonError = BSONError()
bulk = ccall( (:mongoc_collection_create_bulk_operation, libmongoc),
Ptr{Void}, (Ptr{Void}, Bool, Ptr{Void}),
collection._wrap_,
true,
C_NULL )
ccall( (:mongoc_bulk_operation_insert, libmongoc),
Void, (Ptr{Void}, Ptr{Void}),
bulk,
documents._wrap_,
)
reply = BCON_NEW ("i", BCON_INT32 (i))
ret = ccall( (:mongoc_bulk_operation_execute, libmongoc),
Bool, (Ptr{Void}, Ptr{Void}, Ptr{Void}),
bulk._wrap_,
reply._wrap_,
bsonError._wrap_
)
return ret
end
@cwiese Did you actually try the above bulk insert code? How did it work? Any experience since March?
This works for us:
function insert_bulk(collection::MongoCollection, documents::Vector{Mongo.BSONObject}, flags::Int = MongoInsertFlags.None)
#bsonError = BSONError()
bulk = ccall((:mongoc_collection_create_bulk_operation, Mongo.libmongoc),
Ptr{Void}, (Ptr{Void}, Bool, Ptr{Void}),
collection._wrap_, true, C_NULL)
for doc in documents
ccall((:mongoc_bulk_operation_insert, Mongo.libmongoc),
Void, (Ptr{Void}, Ptr{Void}),
bulk, doc._wrap_)
end
#reply = BCON_NEW ("i", BCON_INT32 (i))
reply = BSONObject()
ret = ccall((:mongoc_bulk_operation_execute, Mongo.libmongoc),
Bool, (Ptr{Void}, Ptr{Void}, Ptr{Void}),
bulk,
reply._wrap_,
C_NULL #bsonError._wrap_
)
ccall((:mongoc_bulk_operation_destroy, Mongo.libmongoc),
Void, (Ptr{Void},), bulk)
return ret
end
@cwiese Sorry for the late reply. I just got to a point in my coding to try out your function. It works great on my side, too. Thanks a lot!
Has anyone created a binding for Bulk insert. We are so surprise at how slow insert is. Attempting to create a bulk insert function.