Mongoc.jl
Mongoc.jl copied to clipboard
Pick equivalent Base functions to overload CRUD operations
insert_one
and insert_many
translates naturally to push!
and append!
.
However, I couldn't think of obvious Base
functions equivalent to delete_one
, delete_many
, update_one
, update_many
, find_one
, find
.
Anyone could come up with suggestions?
Perhaps treating some operations like a dictionary where a BSON query is the "key" will work.
# delete_one or delete_many depending on the multi flag
Base.delete!(collection::Collection, filter::BSON; multi=false)
# find_one_and_delete: https://docs.mongodb.com/manual/reference/method/db.collection.findOneAndDelete/
Base.pop!(collection::Collection, filter::BSON)
# find_one_and_replace: https://docs.mongodb.com/manual/reference/method/db.collection.findOneAndReplace/
Base.setindex!(collection::Collection, filter::BSON, doc::BSON)
# find_one
Base.getindex!(collection::Collection, filter::BSON)
# find_one_and_replace with $setOnInsert upsert
Base.get!(collection::Collection, filter::BSON, default::BSON)
It's a bit weird, but it could work.