Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mongoc_bulk_operation_execute #3

Open
cwiese opened this issue Mar 27, 2015 · 4 comments
Open

mongoc_bulk_operation_execute #3

cwiese opened this issue Mar 27, 2015 · 4 comments

Comments

@cwiese
Copy link

cwiese commented Mar 27, 2015

Has anyone created a binding for Bulk insert. We are so surprise at how slow insert is. Attempting to create a bulk insert function.

@cwiese
Copy link
Author

cwiese commented Mar 27, 2015

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

@szalmaf
Copy link

szalmaf commented Sep 3, 2015

@cwiese Did you actually try the above bulk insert code? How did it work? Any experience since March?

@cwiese
Copy link
Author

cwiese commented Sep 3, 2015

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

@szalmaf
Copy link

szalmaf commented Sep 16, 2015

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants