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

Pick equivalent Base functions to overload CRUD operations #7

Open
felipenoris opened this issue Sep 18, 2018 · 1 comment
Open

Pick equivalent Base functions to overload CRUD operations #7

felipenoris opened this issue Sep 18, 2018 · 1 comment
Labels
decision help wanted Extra attention is needed

Comments

@felipenoris
Copy link
Owner

felipenoris commented Sep 18, 2018

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 felipenoris added the help wanted Extra attention is needed label Sep 18, 2018
@felipenoris felipenoris changed the title Find equivalent Base functions to overload CRUD operations Pick equivalent Base functions to overload CRUD operations Mar 10, 2019
@wardlem
Copy link
Contributor

wardlem commented Apr 26, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
decision help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants