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

RUST-1576 Allow "timeseries"-typed collections in list_collections output #814

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ pub enum CollectionType {

/// Indicates that the data store is a collection.
Collection,

/// Indicates that the data store is a timeseries.
Timeseries,
}

/// Info about the collection that is contained in the `CollectionSpecification::info` field of a
Expand Down
1 change: 1 addition & 0 deletions src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod index_management;
#[cfg(all(not(feature = "sync"), not(feature = "tokio-sync")))]
mod lambda_examples;
pub mod spec;
mod timeseries;
pub(crate) mod util;

#[cfg(feature = "in-use-encryption-unstable")]
Expand Down
47 changes: 47 additions & 0 deletions src/test/timeseries.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use bson::doc;
use futures::TryStreamExt;

use crate::{
db::options::{CreateCollectionOptions, TimeseriesOptions},
test::log_uncaptured,
Client,
};

use super::LOCK;

type Result<T> = anyhow::Result<T>;

#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
async fn list_collections_timeseries() -> Result<()> {
let _guard = LOCK.run_exclusively();

let client = Client::test_builder().build().await;
if client.server_version_lt(5, 0) {
log_uncaptured("Skipping list_collections_timeseries: timeseries require server >= 5.0");
return Ok(());
}
let db = client.database("list_collections_timeseries");
db.drop(None).await?;
db.create_collection(
"test",
CreateCollectionOptions::builder()
.timeseries(
TimeseriesOptions::builder()
.time_field("timestamp".to_string())
.meta_field(None)
.granularity(None)
.build(),
)
.build(),
)
.await?;
let results: Vec<_> = db
.list_collections(doc! { "name": "test" }, None)
.await?
.try_collect()
.await?;
assert_eq!(results.len(), 1);

Ok(())
}