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

Method test_distinct

test/test_cursor.py:1202–1222  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1200 self.assertFalse(t.is_alive())
1201
1202 def test_distinct(self):
1203 self.db.drop_collection("test")
1204
1205 self.db.test.insert_many([{"a": 1}, {"a": 2}, {"a": 2}, {"a": 2}, {"a": 3}])
1206
1207 distinct = self.db.test.find({"a": {"$lt": 3}}).distinct("a")
1208 distinct.sort()
1209
1210 self.assertEqual([1, 2], distinct)
1211
1212 self.db.drop_collection("test")
1213
1214 self.db.test.insert_one({"a": {"b": "a"}, "c": 12})
1215 self.db.test.insert_one({"a": {"b": "b"}, "c": 8})
1216 self.db.test.insert_one({"a": {"b": "c"}, "c": 12})
1217 self.db.test.insert_one({"a": {"b": "c"}, "c": 8})
1218
1219 distinct = self.db.test.find({"c": 8}).distinct("a.b")
1220 distinct.sort()
1221
1222 self.assertEqual(["b", "c"], distinct)
1223
1224 def test_with_statement(self):
1225 self.db.drop_collection("test")

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected