forked from samus/mongodb-csharp
/
MongoQueryObject.cs
159 lines (138 loc) · 4.7 KB
/
MongoQueryObject.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System;
using System.Linq.Expressions;
namespace MongoDB.Linq
{
internal class MongoQueryObject
{
private Document _query;
private Document _sort;
/// <summary>
/// Gets or sets the aggregator.
/// </summary>
/// <value>The aggregator.</value>
public LambdaExpression Aggregator { get; set; }
/// <summary>
/// Gets or sets the name of the collection.
/// </summary>
/// <value>The name of the collection.</value>
public string CollectionName { get; set; }
/// <summary>
/// Gets or sets the database.
/// </summary>
/// <value>The database.</value>
public IMongoDatabase Database { get; set; }
/// <summary>
/// Gets or sets the type of the document.
/// </summary>
/// <value>The type of the document.</value>
public Type DocumentType { get; set; }
/// <summary>
/// Gets or sets the fields.
/// </summary>
/// <value>The fields.</value>
public Document Fields { get; set; }
/// <summary>
/// Gets or sets the finalizer function.
/// </summary>
/// <value>The finalizer function.</value>
public string FinalizerFunction { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this is a count query.
/// </summary>
/// <value><c>true</c> if this is a count query; otherwise, <c>false</c>.</value>
public bool IsCount { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance is map reduce.
/// </summary>
/// <value>
/// <c>true</c> if this instance is map reduce; otherwise, <c>false</c>.
/// </value>
public bool IsMapReduce { get; set; }
/// <summary>
/// Gets or sets the map function.
/// </summary>
/// <value>The map function.</value>
public string MapFunction { get; set; }
/// <summary>
/// Gets or sets the reduce function.
/// </summary>
/// <value>The reduce function.</value>
public string ReduceFunction { get; set; }
/// <summary>
/// Gets or sets the number to skip.
/// </summary>
/// <value>The number to skip.</value>
public int NumberToSkip { get; set; }
/// <summary>
/// Gets or sets the number to limit.
/// </summary>
/// <value>The number to limit.</value>
public int NumberToLimit { get; set; }
/// <summary>
/// Gets or sets the projector.
/// </summary>
/// <value>The projector.</value>
public LambdaExpression Projector { get; set; }
/// <summary>
/// Gets or sets the query.
/// </summary>
/// <value>The query.</value>
public Document Query
{
get { return _query; }
}
/// <summary>
/// Gets the sort.
/// </summary>
/// <value>The sort.</value>
public Document Sort
{
get { return _sort; }
}
/// <summary>
/// Initializes a new instance of the <see cref="MongoQueryObject"/> class.
/// </summary>
public MongoQueryObject()
{
Fields = new Document();
_query = new Document();
}
/// <summary>
/// Adds the sort.
/// </summary>
/// <param name="name">The name.</param>
/// <param name="value">The value.</param>
public void AddSort(string name, int value)
{
if(_sort == null)
_sort = new Document();
_sort.Add(name, value);
}
/// <summary>
/// Sets the query document.
/// </summary>
/// <param name="document">The document.</param>
public void SetQueryDocument(Document document)
{
_query = document;
}
/// <summary>
/// Sets the where clause.
/// </summary>
/// <param name="whereClause">The where clause.</param>
public void SetWhereClause(string whereClause)
{
_query = Op.Where(whereClause);
}
/// <summary>
/// Returns a <see cref="System.String"/> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> that represents this instance.
/// </returns>
public override string ToString()
{
return "queryobject";
}
}
}