-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Batch document creation? #75
Comments
As of now, the answer is no. However, there is a short-term workaround, as well as a long-term solution.
Would you be interested in opening a PR for that long-term solution? Should be quite minimal, all things considered. |
Working on a PR. I'm a little stuck right now. I want to add a method like /// Inserts all model instances as documents, provided in some (rust) collection of
/// instances which can be iterated over (e.g. `Vec`, `HashSet`, etc).
///
/// Wraps the driver's `Collection.insert_many` method.
async fn insert_many<O, D, M>(db: &Database, documents: D, options: O) -> Result<InsertManyResult>
where
D: IntoIterator<Item = Document> + Send,
O: Into<Option<options::InsertManyOptions>> + Send,
{
Ok(Self::collection(db).insert_many(documents, options).await?)
} So that any collection the user happens to end up with is suitable for batch insertion directly, so long as the collection is iterable and the iterator items can be converted into documents. I go on to provide an path for implicit conversion: impl<M: Model> From<M> for Document {
fn from(model: M) -> Document {
model.document_from_instance()
}
} The type system is not happy with me:
Is this the right way to handle an unknown iterator which yields some item /which can be converted to a document/? Hoping you can give me some advice, I've never found myself in this particular situation in Rust before. |
Yea, so the issue is that
We shouldn't need that That should help. |
Hello,
I am wondering if there is a more efficient interface to create a large number of documents at once, all of the same type.
For
N
documents I can simply performN
.save()
calls, and wait on all the futures in parallel, but I am wondering if there is something faster (send them all in one request) / more elegant available in Wither that I did not see.Thank you.
The text was updated successfully, but these errors were encountered: