Mongoc.jl icon indicating copy to clipboard operation
Mongoc.jl copied to clipboard

Pick equivalent Base functions to overload CRUD operations

Open felipenoris opened this issue 6 years ago • 1 comments

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?

felipenoris avatar Sep 18 '18 02:09 felipenoris

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.

wardlem avatar Apr 26 '21 13:04 wardlem