MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / test_distinct

Method test_distinct

test/test_collection.py:1842–1871  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1840 self.assertEqual(0, len(pool.conns))
1841
1842 def test_distinct(self):
1843 self.db.drop_collection("test")
1844
1845 test = self.db.test
1846 test.insert_many([{"a": 1}, {"a": 2}, {"a": 2}, {"a": 2}, {"a": 3}])
1847
1848 distinct = test.distinct("a")
1849 distinct.sort()
1850
1851 self.assertEqual([1, 2, 3], distinct)
1852
1853 distinct = test.find({"a": {"$gt": 1}}).distinct("a")
1854 distinct.sort()
1855 self.assertEqual([2, 3], distinct)
1856
1857 distinct = test.distinct("a", {"a": {"$gt": 1}})
1858 distinct.sort()
1859 self.assertEqual([2, 3], distinct)
1860
1861 self.db.drop_collection("test")
1862
1863 test.insert_one({"a": {"b": "a"}, "c": 12})
1864 test.insert_one({"a": {"b": "b"}, "c": 12})
1865 test.insert_one({"a": {"b": "c"}, "c": 12})
1866 test.insert_one({"a": {"b": "c"}, "c": 12})
1867
1868 distinct = test.distinct("a.b")
1869 distinct.sort()
1870
1871 self.assertEqual(["a", "b", "c"], distinct)
1872
1873 def test_query_on_query_field(self):
1874 self.db.drop_collection("test")

Callers

nothing calls this directly

Calls 6

drop_collectionMethod · 0.45
insert_manyMethod · 0.45
distinctMethod · 0.45
sortMethod · 0.45
findMethod · 0.45
insert_oneMethod · 0.45

Tested by

no test coverage detected