Skip to content

Commit fde8219

Browse files
committed
Address technical feedback
1 parent dbbabec commit fde8219

File tree

2 files changed

+9
-45
lines changed

2 files changed

+9
-45
lines changed

source/fundamentals/crud/read-operations/project.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ The examples in this guide use the ``sample_restaurants.restaurants`` collection
3131
from the :atlas:`Atlas sample datasets </sample-data>`. To learn how to create a
3232
free MongoDB Atlas cluster and load the sample datasets, see the :ref:`<csharp-quickstart>`.
3333

34-
The examples on this page use the following ``Restaurant`` and ``Address`` classes to model
35-
the documents in the collection:
36-
37-
.. literalinclude:: /includes/fundamentals/code-examples/Project.cs
38-
:start-after: start-model
39-
:end-before: end-model
40-
:language: csharp
41-
4234
Projection Types
4335
----------------
4436

source/includes/fundamentals/code-examples/Project.cs

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using MongoDB.Bson.Serialization.Conventions;
44
using MongoDB.Driver;
55

6-
public class LimitSortSkip
6+
public class Project
77
{
88
// Replace with your connection string
99
private const string MongoConnectionString = "<connection string URI>";
@@ -12,12 +12,12 @@ public static void Main(string[] args)
1212
{
1313
var mongoClient = new MongoClient(MongoConnectionString);
1414
var database = mongoClient.GetDatabase("sample_restaurants");
15-
var collection = database.GetCollection<Restaurant>("restaurants");
15+
var collection = database.GetCollection<BsonDocument>("restaurants");
1616

1717
{
1818
// start-project-include
19-
var filter = Builders<Restaurant>.Filter.Eq("name", "Emerald Pub");
20-
var projection = Builders<Restaurant>.Projection
19+
var filter = Builders<BsonDocument>.Filter.Eq("name", "Emerald Pub");
20+
var projection = Builders<BsonDocument>.Projection
2121
.Include("name")
2222
.Include("cuisine");
2323

@@ -31,8 +31,8 @@ public static void Main(string[] args)
3131

3232
{
3333
// start-project-include-without-id
34-
var filter = Builders<Restaurant>.Filter.Eq("name", "Emerald Pub");
35-
var projection = Builders<Restaurant>.Projection
34+
var filter = Builders<BsonDocument>.Filter.Eq("name", "Emerald Pub");
35+
var projection = Builders<BsonDocument>.Projection
3636
.Include("name")
3737
.Include("cuisine")
3838
.Exclude("_id");
@@ -47,8 +47,8 @@ public static void Main(string[] args)
4747

4848
{
4949
// start-project-exclude
50-
var filter = Builders<Restaurant>.Filter.Eq("name", "Emerald Pub");
51-
var projection = Builders<Restaurant>.Projection
50+
var filter = Builders<BsonDocument>.Filter.Eq("name", "Emerald Pub");
51+
var projection = Builders<BsonDocument>.Projection
5252
.Exclude("cuisine");
5353

5454
var results = collection.Find(filter).Project(projection).ToList();
@@ -60,32 +60,4 @@ public static void Main(string[] args)
6060
}
6161

6262
}
63-
}
64-
65-
// start-model
66-
public class Restaurant {
67-
public ObjectId? Id { get; set; }
68-
69-
[BsonElement("name")]
70-
public string? Name { get; set; }
71-
72-
[BsonElement("cuisine")]
73-
public string? Cuisine { get; set; }
74-
75-
[BsonElement("address")]
76-
public Address? Address { get; set; }
77-
}
78-
79-
public class Address
80-
{
81-
public string Building { get; set; }
82-
83-
[BsonElement("coord")]
84-
public double[] Coordinates { get; set; }
85-
86-
public string Street { get; set; }
87-
88-
[BsonElement("zipcode")]
89-
public string ZipCode { get; set; }
90-
}
91-
// end-model
63+
}

0 commit comments

Comments
 (0)