Skip to content

Commit c641a38

Browse files
authored
RUST-1576 Allow "timeseries"-typed collections in list_collections output (#814)
1 parent f3f96d3 commit c641a38

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

src/results.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ pub enum CollectionType {
121121

122122
/// Indicates that the data store is a collection.
123123
Collection,
124+
125+
/// Indicates that the data store is a timeseries.
126+
Timeseries,
124127
}
125128

126129
/// Info about the collection that is contained in the `CollectionSpecification::info` field of a

src/test/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ mod index_management;
1515
#[cfg(all(not(feature = "sync"), not(feature = "tokio-sync")))]
1616
mod lambda_examples;
1717
pub mod spec;
18+
mod timeseries;
1819
pub(crate) mod util;
1920

2021
#[cfg(feature = "in-use-encryption-unstable")]

src/test/timeseries.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
use bson::doc;
2+
use futures::TryStreamExt;
3+
4+
use crate::{
5+
db::options::{CreateCollectionOptions, TimeseriesOptions},
6+
test::log_uncaptured,
7+
Client,
8+
};
9+
10+
use super::LOCK;
11+
12+
type Result<T> = anyhow::Result<T>;
13+
14+
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
15+
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
16+
async fn list_collections_timeseries() -> Result<()> {
17+
let _guard = LOCK.run_exclusively();
18+
19+
let client = Client::test_builder().build().await;
20+
if client.server_version_lt(5, 0) {
21+
log_uncaptured("Skipping list_collections_timeseries: timeseries require server >= 5.0");
22+
return Ok(());
23+
}
24+
let db = client.database("list_collections_timeseries");
25+
db.drop(None).await?;
26+
db.create_collection(
27+
"test",
28+
CreateCollectionOptions::builder()
29+
.timeseries(
30+
TimeseriesOptions::builder()
31+
.time_field("timestamp".to_string())
32+
.meta_field(None)
33+
.granularity(None)
34+
.build(),
35+
)
36+
.build(),
37+
)
38+
.await?;
39+
let results: Vec<_> = db
40+
.list_collections(doc! { "name": "test" }, None)
41+
.await?
42+
.try_collect()
43+
.await?;
44+
assert_eq!(results.len(), 1);
45+
46+
Ok(())
47+
}

0 commit comments

Comments
 (0)