@@ -1326,7 +1326,7 @@ find (mongoc_collection_t *collection,
1326
1326
return true;
1327
1327
}
1328
1328
1329
- /* TODO: merge into single_write */
1329
+
1330
1330
static bool
1331
1331
find_one (mongoc_collection_t * collection ,
1332
1332
const bson_t * test ,
@@ -1607,23 +1607,17 @@ list_databases (mongoc_client_t *client,
1607
1607
const bson_t * test ,
1608
1608
const bson_t * operation ,
1609
1609
mongoc_client_session_t * session ,
1610
- const mongoc_read_prefs_t * read_prefs ,
1611
- bson_t * reply ,
1612
- bool name_only )
1610
+ bson_t * reply )
1613
1611
{
1614
1612
mongoc_cursor_t * cursor ;
1615
- bson_t cmd = BSON_INITIALIZER ;
1613
+ bson_t opts ;
1616
1614
1617
1615
BSON_ASSERT (client );
1618
- BSON_APPEND_INT32 (& cmd , "listDatabases" , 1 );
1619
-
1620
- if (name_only ) {
1621
- BSON_APPEND_BOOL (& cmd , "nameOnly" , true);
1622
- }
1616
+ bson_init (& opts );
1617
+ append_session (session , & opts );
1623
1618
1624
- /* ignore client read prefs */
1625
- cursor = _mongoc_cursor_array_new (client , "admin" , & cmd , NULL , "databases" );
1626
- bson_destroy (& cmd );
1619
+ cursor = mongoc_client_find_databases_with_opts (client , & opts );
1620
+ bson_destroy (& opts );
1627
1621
1628
1622
check_cursor (cursor , test , operation );
1629
1623
mongoc_cursor_destroy (cursor );
@@ -1632,80 +1626,73 @@ list_databases (mongoc_client_t *client,
1632
1626
}
1633
1627
1634
1628
1635
- /* TODO: use find_indexes/collection/databases helpers */
1636
1629
static bool
1637
- list_indexes (mongoc_collection_t * collection ,
1638
- const bson_t * test ,
1639
- const bson_t * operation ,
1640
- mongoc_client_session_t * session ,
1641
- const mongoc_read_prefs_t * read_prefs ,
1642
- bson_t * reply ,
1643
- bool name_only )
1630
+ list_database_names (mongoc_client_t * client ,
1631
+ const bson_t * test ,
1632
+ const bson_t * operation ,
1633
+ mongoc_client_session_t * session ,
1634
+ bson_t * reply )
1644
1635
{
1645
- mongoc_cursor_t * cursor ;
1646
- bson_t cmd = BSON_INITIALIZER ;
1647
- bson_t child ;
1636
+ char * * database_names ;
1637
+ bson_t opts ;
1648
1638
bson_error_t error ;
1649
1639
1650
- BSON_ASSERT (collection );
1640
+ BSON_ASSERT (client );
1641
+ bson_init (& opts );
1642
+ append_session (session , & opts );
1651
1643
1652
- bson_append_utf8 (& cmd ,
1653
- "listIndexes" ,
1654
- -1 ,
1655
- collection -> collection ,
1656
- collection -> collectionlen );
1644
+ database_names =
1645
+ mongoc_client_get_database_names_with_opts (client , & opts , & error );
1646
+ bson_destroy (& opts );
1657
1647
1658
- if (name_only ) {
1659
- BSON_APPEND_BOOL (& cmd , "nameOnly" , true);
1660
- }
1648
+ check_result (
1649
+ test , operation , database_names != NULL , NULL /* result */ , & error );
1650
+ bson_init (reply );
1651
+ bson_strfreev (database_names );
1652
+ return true;
1653
+ }
1661
1654
1662
- BSON_APPEND_DOCUMENT_BEGIN (& cmd , "cursor" , & child );
1663
- bson_append_document_end (& cmd , & child );
1664
1655
1665
- /* No read preference. Index Enumeration Spec: "run listIndexes on the
1666
- * primary node in replicaSet mode". */
1667
- cursor = _mongoc_cursor_cmd_new (
1668
- collection -> client , collection -> ns , & cmd , NULL , NULL , NULL , NULL );
1656
+ static bool
1657
+ list_indexes (mongoc_collection_t * collection ,
1658
+ const bson_t * test ,
1659
+ const bson_t * operation ,
1660
+ mongoc_client_session_t * session ,
1661
+ bson_t * reply )
1662
+ {
1663
+ bson_t opts ;
1664
+ mongoc_cursor_t * cursor ;
1669
1665
1670
- if (!mongoc_cursor_error (cursor , & error )) {
1671
- _mongoc_cursor_prime (cursor );
1672
- }
1666
+ BSON_ASSERT (collection );
1673
1667
1674
- bson_destroy (& cmd );
1668
+ bson_init (& opts );
1669
+ append_session (session , & opts );
1675
1670
1671
+ cursor = mongoc_collection_find_indexes_with_opts (collection , & opts );
1676
1672
check_cursor (cursor , test , operation );
1677
1673
mongoc_cursor_destroy (cursor );
1678
1674
bson_init (reply );
1675
+ bson_destroy (& opts );
1679
1676
return true;
1680
1677
}
1681
1678
1682
1679
1683
1680
static bool
1684
- list_collections (mongoc_client_t * client ,
1681
+ list_collections (mongoc_database_t * db ,
1685
1682
const bson_t * test ,
1686
1683
const bson_t * operation ,
1687
1684
mongoc_client_session_t * session ,
1688
- const mongoc_read_prefs_t * read_prefs ,
1689
- bson_t * reply ,
1690
- bool name_only )
1685
+ bson_t * reply )
1691
1686
{
1692
1687
mongoc_cursor_t * cursor ;
1693
- bson_t cmd = BSON_INITIALIZER ;
1688
+ bson_t opts ;
1694
1689
1695
- BSON_APPEND_INT32 (& cmd , "listCollections" , 1 );
1690
+ bson_init (& opts );
1691
+ append_session (session , & opts );
1696
1692
1697
- if (name_only ) {
1698
- BSON_APPEND_BOOL (& cmd , "nameOnly" , true);
1699
- }
1693
+ cursor = mongoc_database_find_collections_with_opts (db , & opts );
1700
1694
1701
- /* Enumerate Collections Spec: "run listCollections on the primary node in
1702
- * replicaset mode" */
1703
- cursor =
1704
- _mongoc_cursor_cmd_new (client , "admin" , & cmd , NULL , NULL , NULL , NULL );
1705
- if (cursor -> error .domain == 0 ) {
1706
- _mongoc_cursor_prime (cursor );
1707
- }
1708
- bson_destroy (& cmd );
1695
+ bson_destroy (& opts );
1709
1696
1710
1697
check_cursor (cursor , test , operation );
1711
1698
mongoc_cursor_destroy (cursor );
@@ -1714,6 +1701,33 @@ list_collections (mongoc_client_t *client,
1714
1701
return true;
1715
1702
}
1716
1703
1704
+ static bool
1705
+ list_collection_names (mongoc_database_t * db ,
1706
+ const bson_t * test ,
1707
+ const bson_t * operation ,
1708
+ mongoc_client_session_t * session ,
1709
+ bson_t * reply )
1710
+ {
1711
+ char * * collection_names ;
1712
+ bson_t opts ;
1713
+ bson_error_t error ;
1714
+
1715
+ bson_init (& opts );
1716
+ append_session (session , & opts );
1717
+
1718
+ collection_names =
1719
+ mongoc_database_get_collection_names_with_opts (db , & opts , & error );
1720
+
1721
+ bson_destroy (& opts );
1722
+
1723
+ check_result (
1724
+ test , operation , collection_names != NULL , NULL /* result */ , & error );
1725
+ bson_init (reply );
1726
+ bson_strfreev (collection_names );
1727
+
1728
+ return true;
1729
+ }
1730
+
1717
1731
1718
1732
static bool
1719
1733
gridfs_download (mongoc_database_t * db ,
@@ -1745,19 +1759,6 @@ gridfs_download (mongoc_database_t *db,
1745
1759
return true;
1746
1760
}
1747
1761
1748
- /* The download_by_name functionality is part of the Advanced API for GridFS
1749
- * and the C Driver hasn't implemented the Advanced API yet. This is a
1750
- * placeholder to be used when the download_by_name is implemented. */
1751
- static bool
1752
- gridfs_download_by_name ()
1753
- {
1754
- test_error ("The download_by_name functionality is part of the Advanced API "
1755
- "for GridFS and the C Driver hasn't implemented the Advanced "
1756
- "API yet." );
1757
- return false;
1758
- }
1759
-
1760
-
1761
1762
bool
1762
1763
json_test_operation (json_test_ctx_t * ctx ,
1763
1764
const bson_t * test ,
@@ -1837,18 +1838,17 @@ json_test_operation (json_test_ctx_t *ctx,
1837
1838
res = find_one (c , test , operation , session , read_prefs , reply );
1838
1839
} else if (!strcmp (op_name , "aggregate" )) {
1839
1840
res = aggregate (c , test , operation , session , read_prefs , reply );
1840
- } else if (!strcmp (op_name , "listIndexNames" )) {
1841
- res =
1842
- list_indexes (c , test , operation , session , read_prefs , reply , true);
1843
1841
} else if (!strcmp (op_name , "listIndexes" )) {
1844
- res = list_indexes (
1845
- c , test , operation , session , read_prefs , reply , false);
1842
+ res = list_indexes (c , test , operation , session , reply );
1846
1843
} else if (!strcmp (op_name , "watch" )) {
1847
1844
bson_t pipeline = BSON_INITIALIZER ;
1848
1845
mongoc_change_stream_destroy (ctx -> change_stream );
1849
1846
ctx -> change_stream = mongoc_collection_watch (c , & pipeline , NULL );
1850
1847
bson_init (reply );
1851
1848
bson_destroy (& pipeline );
1849
+ } else if (!strcmp (op_name , "mapReduce" ) ||
1850
+ !strcmp (op_name , "listIndexNames" )) {
1851
+ test_error ("operation not implemented in libmongoc" );
1852
1852
} else {
1853
1853
test_error ("unrecognized collection operation name %s" , op_name );
1854
1854
}
@@ -1857,19 +1857,18 @@ json_test_operation (json_test_ctx_t *ctx,
1857
1857
res = db_aggregate (db , test , operation , session , read_prefs , reply );
1858
1858
} else if (!strcmp (op_name , "runCommand" )) {
1859
1859
res = command (db , test , operation , session , read_prefs , reply );
1860
- } else if (!strcmp (op_name , "listCollections" ) ||
1861
- !strcmp (op_name , "listCollectionObjects" )) {
1862
- res = list_collections (
1863
- c -> client , test , operation , session , read_prefs , reply , false);
1860
+ } else if (!strcmp (op_name , "listCollections" )) {
1861
+ res = list_collections (db , test , operation , session , reply );
1864
1862
} else if (!strcmp (op_name , "listCollectionNames" )) {
1865
- res = list_collections (
1866
- c -> client , test , operation , session , read_prefs , reply , true);
1863
+ res = list_collection_names (db , test , operation , session , reply );
1867
1864
} else if (!strcmp (op_name , "watch" )) {
1868
1865
bson_t pipeline = BSON_INITIALIZER ;
1869
1866
mongoc_change_stream_destroy (ctx -> change_stream );
1870
1867
ctx -> change_stream = mongoc_database_watch (db , & pipeline , NULL );
1871
1868
bson_init (reply );
1872
1869
bson_destroy (& pipeline );
1870
+ } else if (!strcmp (op_name , "listCollectionObjects" )) {
1871
+ test_error ("listCollectionObjects is not implemented in libmongoc" );
1873
1872
} else {
1874
1873
test_error ("unrecognized database operation name %s" , op_name );
1875
1874
}
@@ -1905,19 +1904,18 @@ json_test_operation (json_test_ctx_t *ctx,
1905
1904
test_error ("unrecognized session operation name %s" , op_name );
1906
1905
}
1907
1906
} else if (!strcmp (obj_name , "client" )) {
1908
- if (!strcmp (op_name , "listDatabases" ) ||
1909
- !strcmp (op_name , "listDatabaseObjects" )) {
1910
- res = list_databases (
1911
- c -> client , test , operation , session , read_prefs , reply , false);
1907
+ if (!strcmp (op_name , "listDatabases" )) {
1908
+ res = list_databases (c -> client , test , operation , session , reply );
1912
1909
} else if (!strcmp (op_name , "listDatabaseNames" )) {
1913
- res = list_databases (
1914
- c -> client , test , operation , session , read_prefs , reply , true);
1910
+ res = list_database_names (c -> client , test , operation , session , reply );
1915
1911
} else if (!strcmp (op_name , "watch" )) {
1916
1912
bson_t pipeline = BSON_INITIALIZER ;
1917
1913
mongoc_change_stream_destroy (ctx -> change_stream );
1918
1914
ctx -> change_stream = mongoc_client_watch (c -> client , & pipeline , NULL );
1919
1915
bson_init (reply );
1920
1916
bson_destroy (& pipeline );
1917
+ } else if (!strcmp (op_name , "listDatabaseObjects" )) {
1918
+ test_error ("listDatabaseObjects is not implemented in libmongoc" );
1921
1919
} else {
1922
1920
test_error ("unrecognized client operation name %s" , op_name );
1923
1921
}
@@ -1926,8 +1924,8 @@ json_test_operation (json_test_ctx_t *ctx,
1926
1924
res =
1927
1925
gridfs_download (db , test , operation , session , read_prefs , reply );
1928
1926
} else if (!strcmp (op_name , "download_by_name" )) {
1929
- res = gridfs_download_by_name ();
1930
- bson_init ( reply );
1927
+ test_error ( "download_by_name is part of the optional advanced API "
1928
+ "and not implemented in libmongoc" );
1931
1929
} else {
1932
1930
test_error ("unrecognized gridfs operation name %s" , op_name );
1933
1931
}
0 commit comments