Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix merge errors. Lot of test currently failing.

  • Loading branch information...
commit 25bfc6c542800010b8c39b9c104aec07baa5b9cc 1 parent 0359ec7
@lanwin lanwin authored
View
6 MongoDB.Net-Tests/MongoDB.Driver.Tests.csproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -51,7 +51,7 @@
<DefineConstants>TRACE;DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
- <NoWarn>618</NoWarn>
+ <NoWarn>618, 1718</NoWarn>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
@@ -198,4 +198,4 @@
</None>
</ItemGroup>
<ItemGroup />
-</Project>
+</Project>
View
381 MongoDBDriver/Collection.cs
@@ -1,381 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using MongoDB.Driver.Connections;
-using MongoDB.Driver.Protocol;
-
-namespace MongoDB.Driver
-{
- public class Collection : IMongoCollection
- {
- private Connection connection;
-
- private string name;
- public string Name {
- get { return name; }
- }
-
- private string dbName;
- public string DbName {
- get { return dbName; }
- }
-
- public string FullName {
- get { return dbName + "." + name; }
- }
-
- private CollectionMetaData metaData;
- public CollectionMetaData MetaData {
- get {
- if (metaData == null) {
- metaData = new CollectionMetaData(this.dbName, this.name, this.connection);
- }
- return metaData;
- }
- }
-
- private Database db;
- private Database Db {
- get {
- if (db == null)
- db = new Database(this.connection, this.dbName);
- return db;
- }
- }
- public Collection(string name, Connection conn, string dbName) {
- this.name = name;
- this.connection = conn;
- this.dbName = dbName;
- }
-
- /// <summary>
- /// Finds and returns the first document in a query.
- /// </summary>
- /// <param name="spec">
- /// A <see cref="Document"/> representing the query.
- /// </param>
- /// <returns>
- /// A <see cref="Document"/> from the collection.
- /// </returns>
- public Document FindOne(Document spec) {
- ICursor cur = this.Find(spec, -1, 0, null);
- foreach (Document doc in cur.Documents) {
- cur.Dispose();
- return doc;
- }
- //FIXME Decide if this should throw a not found exception instead of returning null.
- return null;
- //this.Find(spec, -1, 0, null)[0];
- }
-
- public ICursor FindAll() {
- Document spec = new Document();
- return this.Find(spec, 0, 0, null);
- }
-
- public ICursor Find(String @where) {
- Document spec = new Document();
- spec.Append("$where", new Code(@where));
- return this.Find(spec, 0, 0, null);
- }
-
- public ICursor Find(Document spec) {
- return this.Find(spec, 0, 0, null);
- }
-
- public ICursor Find(Document spec, int limit, int skip) {
- return this.Find(spec, limit, skip, null);
- }
-
- public ICursor Find(Document spec, int limit, int skip, Document fields) {
- if (spec == null)
- spec = new Document();
- Cursor cur = new Cursor(connection, this.FullName, spec, limit, skip, fields);
- return cur;
- }
-
- /// <summary>
- /// Finds, modifies and returns a document based on query, spec and sorting
- /// </summary>
- /// <returns>
- /// A <see cref="Document"/>
- /// </returns>
- public Document FindAndModify(Document doc, Document spec) {
- return FindAndModify(doc, spec, false);
- }
-
- public Document FindAndModify(Document doc, Document spec, Document sort) {
- return FindAndModify(doc, spec, sort);
- }
-
- public Document FindAndModify(Document doc, Document spec, bool returnNewDoc) {
- return FindAndModify(doc, spec, new Document(), returnNewDoc);
- }
-
- public Document FindAndModify(Document doc, Document spec, Document sort, bool returnNewDoc) {
- try {
- Document response = this.Db.SendCommand(new Document{
- {"findandmodify", this.Name},
- {"query", spec},
- {"update", EnsureUpdateDocument(doc)},
- {"sort", sort},
- {"new", returnNewDoc}});
-
- return response["value"] as Document;
- } catch (MongoCommandException) {
- // This is when there is no document to operate on
- return null;
- }
- }
-
- /// <summary>
- /// Entrypoint into executing a map/reduce query against the collection.
- /// </summary>
- /// <returns>
- /// A <see cref="MapReduce"/>
- /// </returns>
- public MapReduce MapReduce() {
- return new MapReduce(this.Db, this.Name);
- }
-
- public MapReduceBuilder MapReduceBuilder() {
- return new MapReduceBuilder(this.MapReduce());
- }
-
-
- /// <summary>
- ///Count all items in the collection.
- /// </summary>
- public long Count() {
- return this.Count(new Document());
- }
-
- /// <summary>
- /// Count all items in a collection that match the query spec.
- /// </summary>
- /// <remarks>
- /// It will return 0 if the collection doesn't exist yet.
- /// </remarks>
- public long Count(Document spec) {
- try {
- //Database db = new Database(this.connection, this.dbName);
- Document ret = this.Db.SendCommand(new Document().Append("count", this.Name).Append("query", spec));
- double n = (double)ret["n"];
- return Convert.ToInt64(n);
- } catch (MongoCommandException) {
- //FIXME This is an exception condition when the namespace is missing.
- //-1 might be better here but the console returns 0.
- return 0;
- }
-
- }
-
- /// <summary>
- /// Inserts the Document into the collection.
- /// </summary>
- public void Insert(Document doc, bool safemode) {
- Insert(doc);
- CheckError(safemode);
- }
-
- public void Insert(Document doc) {
- Document[] docs = new Document[] { doc };
- this.Insert(docs);
- }
-
- public void Insert(IEnumerable<Document> docs, bool safemode) {
- if (safemode)
- this.Db.ResetError();
- this.Insert(docs);
- CheckPreviousError(safemode);
- }
-
- public void Insert(IEnumerable<Document> docs) {
- InsertMessage im = new InsertMessage();
- im.FullCollectionName = this.FullName;
- List<Document> idocs = new List<Document>();
- foreach (Document doc in docs) {
- if (doc.Contains("_id") == false) {
- Oid _id = Oid.NewOid();
- doc.Prepend("_id", _id);
- }
- }
- idocs.AddRange(docs);
- im.Documents = idocs.ToArray();
- try {
- this.connection.SendMessage(im);
- } catch (IOException ioe) {
- throw new MongoCommException("Could not insert document, communication failure", this.connection, ioe);
- }
- }
-
- /// <summary>
- /// Deletes documents from the collection according to the spec.
- /// </summary>
- /// <remarks>An empty document will match all documents in the collection and effectively truncate it.
- /// </remarks>
- public void Delete(Document selector, bool safemode) {
- Delete(selector);
- CheckError(safemode);
- }
-
- /// <summary>
- /// Deletes documents from the collection according to the spec.
- /// </summary>
- /// <remarks>An empty document will match all documents in the collection and effectively truncate it.
- /// </remarks>
- public void Delete(Document selector) {
- DeleteMessage dm = new DeleteMessage();
- dm.FullCollectionName = this.FullName;
- dm.Selector = selector;
- try {
- this.connection.SendMessage(dm);
- } catch (IOException ioe) {
- throw new MongoCommException("Could not delete document, communication failure", this.connection, ioe);
- }
- }
-
-
- public void Update(Document doc, bool safemode) {
- Update(doc);
- CheckError(safemode);
- }
-
- /// <summary>
- /// Saves a document to the database using an upsert.
- /// </summary>
- /// <remarks>
- /// The document will contain the _id that is saved to the database. This is really just an alias
- /// to Update(Document) to maintain consistency between drivers.
- /// </remarks>
- public void Save(Document doc) {
- //Try to generate a selector using _id for an existing document.
- //otherwise just set the upsert flag to 1 to insert and send onward.
- Document selector = new Document();
- int upsert = 0;
- if (doc.Contains("_id") & doc["_id"] != null) {
- selector["_id"] = doc["_id"];
- } else {
- //Likely a new document
- Oid id = Oid.NewOid();
- selector["_id"] = id;
- doc.Prepend("_id", id);
- upsert = 1;
- }
- this.Update(doc, selector, upsert);
- }
-
- /// <summary>
- /// Updates a document with the data in doc as found by the selector.
- /// </summary>
- /// <remarks>
- /// _id will be used in the document to create a selector. If it isn't in
- /// the document then it is assumed that the document is new and an upsert is sent to the database
- /// instead.
- /// </remarks>
- [Obsolete("Switch to Save(Document)")]
- public void Update(Document doc) {
- Save(doc);
- }
-
- public void Update(Document doc, Document selector, bool safemode) {
- Update(doc, selector, 0, safemode);
- }
-
- /// <summary>
- /// Updates a document with the data in doc as found by the selector.
- /// </summary>
- public void Update(Document doc, Document selector) {
- this.Update(doc, selector, 0);
- }
-
- public void Update(Document doc, Document selector, UpdateFlags flags, bool safemode) {
- Update(doc, selector, flags);
- CheckError(safemode);
- }
-
- /// <summary>
- /// Updates a document with the data in doc as found by the selector.
- /// </summary>
- /// <param name="doc">The <see cref="Document"/> to update with
- /// </param>
- /// <param name="selector">
- /// The query spec to find the document to update.
- /// </param>
- /// <param name="flags">
- /// <see cref="UpdateFlags"/>
- /// </param>
- public void Update(Document doc, Document selector, UpdateFlags flags) {
- UpdateMessage um = new UpdateMessage();
- um.FullCollectionName = this.FullName;
- um.Selector = selector;
- um.Document = doc;
- um.Flags = (int)flags;
- try {
- this.connection.SendMessage(um);
- } catch (IOException ioe) {
- throw new MongoCommException("Could not update document, communication failure", this.connection, ioe);
- }
-
- }
-
- public void Update(Document doc, Document selector, int flags, bool safemode) {
- Update(doc, selector, flags);
- CheckError(safemode);
- }
-
- public void Update(Document doc, Document selector, int flags) {
- //TODO Update the interface and make a breaking change.
- this.Update(doc, selector, (UpdateFlags)flags);
- }
-
- private Document EnsureUpdateDocument(Document doc) {
- bool foundOp = false;
- foreach (string key in doc.Keys) {
- if (key.IndexOf('$') == 0) {
- foundOp = true;
- break;
- }
- }
- if (foundOp == false) {
- //wrap document in a $set.
- doc = new Document().Append("$set", doc);
- }
- return doc;
- }
-
- /// <summary>
- /// Runs a multiple update query against the database. It will wrap any
- /// doc with $set if the passed in doc doesn't contain any '$' ops.
- /// </summary>
- /// <param name="doc"></param>
- /// <param name="selector"></param>
- public void UpdateAll(Document doc, Document selector) {
- this.Update(EnsureUpdateDocument(doc), selector, UpdateFlags.MultiUpdate);
- }
-
-
- public void UpdateAll(Document doc, Document selector, bool safemode) {
- if (safemode)
- this.Db.ResetError();
- this.UpdateAll(doc, selector);
- CheckPreviousError(safemode);
- }
-
-
- private void CheckError(bool safemode) {
- if (safemode) {
- Document err = this.Db.GetLastError();
- if (ErrorTranslator.IsError(err))
- throw ErrorTranslator.Translate(err);
- }
- }
- private void CheckPreviousError(bool safemode) {
- if (safemode) {
- Document err = this.Db.GetPreviousError();
- if (ErrorTranslator.IsError(err))
- throw ErrorTranslator.Translate(err);
- }
- }
- }
-}
View
26 MongoDBDriver/Connections/Connection.cs
@@ -1,8 +1,8 @@
using System;
using System.IO;
using MongoDB.Driver.Bson;
-using MongoDB.Driver.CommandResults;
using MongoDB.Driver.Protocol;
+using MongoDB.Driver.Results;
using MongoDB.Driver.Serialization;
namespace MongoDB.Driver.Connections
@@ -281,21 +281,25 @@ private T SendCommandCore<T>(ISerializationFactory factory, string database, Typ
GC.SuppressFinalize(this);
}
+ /// <summary>
+ /// Releases unmanaged and - optionally - managed resources
+ /// </summary>
+ /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing)
{
- if (!disposed)
+ if(disposed)
+ return;
+
+ if (disposing)
{
- if (disposing)
- {
- // Cleanup Managed Resources Here
- Close();
- }
+ // Cleanup Managed Resources Here
+ Close();
+ }
- // Cleanup Unmanaged Resources Here
+ // Cleanup Unmanaged Resources Here
- // Then mark object as disposed
- disposed = true;
- }
+ // Then mark object as disposed
+ disposed = true;
}
}
}
View
207 MongoDBDriver/Database.cs
@@ -1,207 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Security.Cryptography;
-using System.Text;
-using MongoDB.Driver.Connections;
-
-namespace MongoDB.Driver
-{
- public class Database : IMongoDatabase
- {
- private Connection connection;
- private IMongoCollection command;
-
- public Database(string connectionString, String name){
- this.connection = ConnectionFactory.GetConnection(connectionString);
- this.Name = name;
- this.command = this["$cmd"];
- }
-
- public Database(Connection conn, String name){
- this.connection = conn;
- this.Name = name;
- this.command = this["$cmd"];
- }
-
- public string Name { get; private set; }
-
- private DatabaseMetaData metaData;
- public DatabaseMetaData MetaData {
- get { return metaData ?? (metaData = new DatabaseMetaData(this.Name, this.connection)); }
- }
-
- private DatabaseJS js;
- public DatabaseJS JS {
- get { return js ?? (js = new DatabaseJS(this)); }
- }
-
- public List<String> GetCollectionNames(){
- IMongoCollection namespaces = this["system.namespaces"];
- ICursor cursor = namespaces.Find(new Document());
- List<String> names = new List<string>();
- foreach (Document doc in cursor.Documents){
- names.Add((String)doc["name"]); //Fix Me: Should filter built-ins
- }
- return names;
- }
-
- public IMongoCollection this[ String name ] {
- get{
- return this.GetCollection(name);
- }
- }
-
- public IMongoCollection GetCollection(String name){
- IMongoCollection col = new Collection(name, this.connection, this.Name);
- return col;
- }
-
- /// <summary>
- /// Gets the document that a reference is pointing to.
- /// </summary>
- public Document FollowReference(DBRef reference){
- if(reference == null)
- throw new ArgumentNullException("reference", "cannot be null");
- Document query = new Document().Append("_id", reference.Id);
- return this[reference.CollectionName].FindOne(query);
- }
-
- /// <summary>
- /// Most operations do not have a return code in order to save the client from having to wait for results.
- /// GetLastError can be called to retrieve the return code if clients want one.
- /// </summary>
- public Document GetLastError(){
- return SendCommand("getlasterror");
- }
-
- /// <summary>
- /// Retrieves the last error and forces the database to fsync all files before returning.
- /// </summary>
- /// <remarks>Server version 1.3+</remarks>
- public Document GetLastErrorAndFSync(){
- return SendCommand(new Document {{"getlasterror", 1.0},{"fsync", true}});
- }
-
- /// <summary>
- /// Call after sending a bulk operation to the database.
- /// </summary>
- public Document GetPreviousError(){
- return SendCommand("getpreverror");
- }
-
- /// <summary>
- /// Gets the sister database on the same Mongo connection with the given name.
- /// </summary>
- public Database GetSisterDatabase(string sisterDbName){
- return new Database(connection, sisterDbName);
- }
-
- /// <summary>
- /// Resets last error. This is good to call before a bulk operation.
- /// </summary>
- public void ResetError(){
- SendCommand("reseterror");
- }
-
- public Document Eval(string javascript){
- return Eval(javascript, new Document());
- }
-
- public Document Eval(string javascript, Document scope){
- return Eval(new CodeWScope(javascript, scope));
- }
-
- public Document Eval(CodeWScope cw){
- Document cmd = new Document().Append("$eval", cw);
- return SendCommand(cmd);
- }
-
- public Document SendCommand(string command){
- AuthenticateIfRequired();
- return SendCommandCore(command);
- }
-
- public Document SendCommand(Document cmd)
- {
- AuthenticateIfRequired();
- return SendCommandCore(cmd);
- }
-
- private Document SendCommandCore(string command)
- {
- var cmd = new Document().Append(command,1.0);
- return SendCommandCore(cmd);
- }
-
- private Document SendCommandCore(Document cmd)
- {
- Document result = this.command.FindOne(cmd);
- double ok = (double)result["ok"];
- if(ok != 1.0)
- {
- var msg = string.Empty;
- if(result.Contains("msg"))
- {
- msg = (string)result["msg"];
- }
- else if(result.Contains("errmsg"))
- {
- msg = (string)result["errmsg"];
- }
- throw new MongoCommandException(msg, result, cmd);
- }
- return result;
- }
-
- /// <summary>
- /// Authenticates the on first request.
- /// </summary>
- private void AuthenticateIfRequired()
- {
- if(connection.IsAuthenticated)
- return;
-
- var builder = new MongoConnectionStringBuilder(connection.ConnectionString);
-
- if(string.IsNullOrEmpty(builder.Username))
- return;
-
- var nonceResult = SendCommandCore("getnonce");
- var nonce = (String)nonceResult["nonce"];
-
- if(nonce == null)
- throw new MongoException("Error retrieving nonce", null);
-
- var pwd = Hash(builder.Username + ":mongo:" + builder.Password);
- var auth = new Document
- {
- {"authenticate", 1.0},
- {"user", builder.Username},
- {"nonce", nonce},
- {"key", Hash(nonce + builder.Username + pwd)}
- };
- try
- {
- SendCommandCore(auth);
- }
- catch(MongoCommandException exception)
- {
- //Todo: use custom exception?
- throw new MongoException("Authentication faild for " + builder.Username, exception);
- }
-
- connection.MaskAuthenticated();
- }
-
- /// <summary>
- /// Hashes the specified text.
- /// </summary>
- /// <param name="text">The text.</param>
- /// <returns></returns>
- internal static string Hash(string text){
- MD5 md5 = MD5.Create();
- byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(text));
- return BitConverter.ToString(hash).Replace("-","").ToLower();
- }
- }
-}
View
166 MongoDBDriver/DatabaseJS.cs
@@ -1,166 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace MongoDB.Driver{
-
- /// <summary>
- /// Encapsulates and provides access to the serverside javascript stored in db.system.js.
- /// </summary>
- public class DatabaseJS : ICollection<Document>
- {
- //private Connection connection;
- private Database db;
- private IMongoCollection js;
-
- internal DatabaseJS (Database db){
- this.db = db;
- this.js = db["system.js"];
- //Needed for some versions of the db to retrieve the functions.
- js.MetaData.CreateIndex(new Document().Append("_id",1),true);
- }
-
- public Document this[ String name ] {
- get{
- return GetFunction(name);
- }
- set{
- Add(value);
- }
- }
-
- /// <summary>
- /// Gets the document representing the function in the database.
- /// </summary>
- /// <param name="name">
- /// A <see cref="System.String"/>
- /// </param>
- /// <returns>
- /// A <see cref="Document"/>
- /// </returns>
- public Document GetFunction(string name){
- return js.FindOne(new Document().Append("_id", name));
- }
-
- /// <summary>
- /// Returns a listing of the names of all the functions in the database
- /// </summary>
- public List<string> GetFunctionNames(){
- List<string> l = new List<string>();
- foreach(Document d in js.FindAll().Documents){
- l.Add((String)d["_id"]);
- }
- return l;
- }
-
- public void Add (string name, string func){
- Add(name, new Code(func));
- }
-
- public void Add (string name, Code func){
- Add(new Document().Append("_id", name).Append("value", func));
- }
-
- /// <summary>
- /// Store a function in the database with an extended attribute called version.
- /// </summary>
- /// <remarks>Version attributes are an extension to the spec. Function names must be unique
- /// to the database so only one version can be stored at a time. This is most useful for libraries
- /// that store function in the database to make sure that the function they are using is the most
- /// up to date.
- /// </remarks>
- public void Add(string name, Code func, float version){
- Add(new Document().Append("_id", name).Append("value", func).Append("version",version));
- }
-
- /// <summary>
- /// Stores a function in the database.
- /// </summary>
- public void Add (Document item){
- if(js.FindOne(new Document().Append("_id", item["_id"])) != null){
- throw new ArgumentException(String.Format("Function {0} already exists in the database.", item["_id"]));
- }
- js.Insert(item);
- }
-
- /// <summary>
- /// Removes every function in the database.
- /// </summary>
- public void Clear (){
- js.Delete(new Document());
- }
-
- public bool Contains (Document item){
- return Contains((string)item["_id"]);
- }
-
- /// <summary>
- /// Checks to see if a function named name is stored in the database.
- /// </summary>
- /// <param name="name">
- /// A <see cref="System.String"/>
- /// </param>
- /// <returns>
- /// A <see cref="System.Boolean"/>
- /// </returns>
- public bool Contains (string name){
- return GetFunction(name) != null;
- }
-
- /// <summary>
- /// Copies the functions from the database ordered by _id (name) to the array starting at the index.
- /// </summary>
- /// <param name="array">
- /// A <see cref="Document[]"/> array to coppy to
- /// </param>
- /// <param name="arrayIndex">
- /// A <see cref="System.Int32"/>
- /// </param>
- public void CopyTo (Document[] array, int arrayIndex){
- //Document query = new Document().Append("$orderby", new Document().Append("_id", 1));
- int idx = arrayIndex;
- foreach(var doc in js.FindAll().Sort("_id").Skip(arrayIndex).Documents){
- if(idx >= array.Length) break;
- array[idx] = doc;
- idx++;
- }
- }
-
- public void Update(Document item){
- throw new System.NotImplementedException();
- }
-
- public bool Remove (Document item){
- return Remove((string)item["_id"]);
- }
-
- public bool Remove (string name){
- js.Delete(new Document().Append("_id", name));
- return true;
- }
-
- public int Count {
- get {
- long cnt = js.Count();
- if(cnt > int.MaxValue) return int.MaxValue; //lots of functions.
- return (int)cnt;
- }
- }
-
- public bool IsReadOnly {
- get {
- return false;
- }
- }
-
- public IEnumerator<Document> GetEnumerator (){
- foreach(Document doc in js.FindAll().Documents){
- yield return doc;
- }
- yield break;
- }
-
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator (){
- return GetEnumerator();
- }
- }
-}
View
12 MongoDBDriver/Document.cs
@@ -245,17 +245,7 @@ public Document Merge(Document source)
return this;
}
-
-
- public Document Update(Document @from) {
- //TODO: Decide if this is needed.
- if(@from == null)
- return this;
- foreach(String key in @from.Keys) {
- this[key] = @from[key];
- }
- return this;
- }
+
/// <summary>
/// Determines whether [contains] [the specified key].
/// </summary>
View
25 MongoDBDriver/IMongo.cs
@@ -1,7 +1,8 @@
-using System;
-
namespace MongoDB.Driver
-{
+{
+ /// <summary>
+ ///
+ /// </summary>
public interface IMongo
{
/// <summary>
@@ -9,19 +10,22 @@ public interface IMongo
/// </summary>
/// <value>The connection string.</value>
string ConnectionString { get; }
+
/// <summary>
/// Gets the named database.
/// </summary>
/// <param name="name">The name.</param>
/// <returns></returns>
- IMongoDatabase GetDatabase(String name);
- /// <summary>
- /// Gets the <see cref="MongoDB.Driver.Database"></see> with the specified name.
- /// </summary>
- /// <value></value>
- IMongoDatabase this[String name] {
+ IMongoDatabase GetDatabase(string name);
+
+ /// <summary>
+ /// Gets the <see cref="MongoDB.Driver.IMongoDatabase"></see> with the specified name.
+ /// </summary>
+ /// <value></value>
+ IMongoDatabase this[string name] {
get;
}
+
/// <summary>
/// Connects this instance.
/// </summary>
@@ -33,10 +37,11 @@ public interface IMongo
/// </summary>
/// <returns></returns>
bool TryConnect();
+
/// <summary>
/// Disconnects this instance.
/// </summary>
/// <returns></returns>
- Boolean Disconnect();
+ bool Disconnect();
}
}
View
77 MongoDBDriver/IMongoCollection.cs
@@ -76,77 +76,48 @@ public interface IMongoCollection
/// <param name = "fields">The fields.</param>
/// <returns></returns>
ICursor Find(Document spec, int limit, int skip, Document fields);
-
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
- /// <param name="doc">
- /// <see cref="Document"/> to use when applying the update.
- /// </param>
- /// <param name="spec">
- /// <see cref="Document"/> to find the document.
- /// </param>
- /// <returns>
- /// A <see cref="Document"/>
- /// </returns>
- Document FindAndModify(Document doc, Document spec);
-
+ /// <param name="document">The document.</param>
+ /// <param name="spec"><see cref="Document"/> to find the document.</param>
+ /// <returns>A <see cref="Document"/></returns>
+ Document FindAndModify(Document document, Document spec);
+
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
- /// <param name="doc">
- /// <see cref="Document"/> to use when applying the update.
- /// </param>
- /// <param name="spec">
- /// <see cref="Document"/> to find the document.
- /// </param>
- /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
+ /// <param name="document">The document.</param>
+ /// <param name="spec"><see cref="Document"/> to find the document.</param>
+ /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the</param>
+ /// <returns>A <see cref="Document"/></returns>
/// <see cref="IndexOrder"/>
- /// <returns>
- /// A <see cref="Document"/>
- /// </returns>
- Document FindAndModify(Document doc, Document spec, Document sort);
-
+ Document FindAndModify(Document document, Document spec, Document sort);
+
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
- /// <param name="doc">
- /// <see cref="Document"/> to use when applying the update.
- /// </param>
- /// <param name="spec">
- /// <see cref="Document"/> to find the document.
- /// </param>
- /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
- /// <see cref="IndexOrder"/>
- /// </param>
- /// <returns>
- /// A <see cref="Document"/>
- /// </returns>
- Document FindAndModify(Document doc, Document spec, bool ReturnNew);
-
+ /// <param name="document">The document.</param>
+ /// <param name="spec"><see cref="Document"/> to find the document.</param>
+ /// <param name="returnNew">if set to <c>true</c> [return new].</param>
+ /// <returns>A <see cref="Document"/></returns>
+ Document FindAndModify(Document document, Document spec, bool returnNew);
+
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
- /// <param name="doc">
- /// <see cref="Document"/> to use when applying the update.
- /// </param>
- /// <param name="spec">
- /// <see cref="Document"/> to find the document.
- /// </param>
- /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
- /// <see cref="IndexOrder"/>
- /// </param>
- /// <param name="ReturnNew">By default the original unmodified document is returned. Pass in true to override this and
- /// get the modified document back.
- /// <returns>
- /// A <see cref="Document"/>
- /// </returns>
- Document FindAndModify(Document doc, Document spec, Document sort, bool ReturnNew);
+ /// <param name="document">The document.</param>
+ /// <param name="spec"><see cref="Document"/> to find the document.</param>
+ /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
+ /// <see cref="IndexOrder"/></param>
+ /// <param name="returnNew">if set to <c>true</c> [return new].</param>
+ /// <returns>A <see cref="Document"/></returns>
+ Document FindAndModify(Document document, Document spec, Document sort, bool returnNew);
/// <summary>
/// Maps the reduce.
View
78 MongoDBDriver/IMongoCollection_1.cs
@@ -88,76 +88,48 @@ public interface IMongoCollection<T> where T : class
/// </summary>
[Obsolete("Use the fluent interface on ICursor for specifying limit and skip Find.Skip(x).Limit(y)")]
ICursor<T> Find(object spec, int limit, int skip, object fields);
-
+
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
- /// <param name="doc">
- /// <see cref="Document"/> to use when applying the update.
- /// </param>
- /// <param name="spec">
- /// <see cref="Document"/> to find the document.
- /// </param>
- /// <returns>
- /// A <see cref="Document"/>
- /// </returns>
- T FindAndModify(object doc, object spec);
-
+ /// <param name="document">The document.</param>
+ /// <param name="spec"><see cref="Document"/> to find the document.</param>
+ /// <returns>A <see cref="Document"/></returns>
+ T FindAndModify(object document, object spec);
+
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
- /// <param name="doc">
- /// <see cref="Document"/> to use when applying the update.
- /// </param>
- /// <param name="spec">
- /// <see cref="Document"/> to find the document.
- /// </param>
- /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
+ /// <param name="document">The document.</param>
+ /// <param name="spec"><see cref="Document"/> to find the document.</param>
+ /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the</param>
+ /// <returns>A <see cref="Document"/></returns>
/// <see cref="IndexOrder"/>
- /// <returns>
- /// A <see cref="Document"/>
- /// </returns>
- T FindAndModify(object doc, object spec, object sort);
-
+ T FindAndModify(object document, object spec, object sort);
+
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
- /// <param name="doc">
- /// <see cref="Document"/> to use when applying the update.
- /// </param>
- /// <param name="spec">
- /// <see cref="Document"/> to find the document.
- /// </param>
- /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
- /// <see cref="IndexOrder"/>
- /// </param>
- /// <returns>
- /// A <see cref="Document"/>
- /// </returns>
- T FindAndModify(object doc, object spec, bool ReturnNew);
-
+ /// <param name="document">The document.</param>
+ /// <param name="spec"><see cref="Document"/> to find the document.</param>
+ /// <param name="returnNew">if set to <c>true</c> [return new].</param>
+ /// <returns>A <see cref="Document"/></returns>
+ T FindAndModify(object document, object spec, bool returnNew);
+
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
- /// <param name="doc">
- /// <see cref="Document"/> to use when applying the update.
- /// </param>
- /// <param name="spec">
- /// <see cref="Document"/> to find the document.
- /// </param>
- /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
- /// <see cref="IndexOrder"/>
- /// </param>
- /// <param name="ReturnNew">By default the original unmodified document is returned. Pass in true to override this and
- /// get the modified document back.
- /// <returns>
- /// A <see cref="Document"/>
- /// </returns>
- T FindAndModify(object doc, object spec, object sort, bool ReturnNew);
+ /// <param name="document">The document.</param>
+ /// <param name="spec"><see cref="Document"/> to find the document.</param>
+ /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
+ /// <see cref="IndexOrder"/></param>
+ /// <param name="returnNew">if set to <c>true</c> [return new].</param>
+ /// <returns>A <see cref="Document"/></returns>
+ T FindAndModify(object document, object spec, object sort, bool returnNew);
/// <summary>
/// Entrypoint into executing a map/reduce query against the collection.
View
1  MongoDBDriver/IMongoDatabase.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using MongoDB.Driver.CommandResults;
namespace MongoDB.Driver
{
View
61 MongoDBDriver/MongoCollection.cs
@@ -120,28 +120,59 @@ public MongoCollection(ISerializationFactory serializationFactory, Connection co
public ICursor Find(Document spec, int limit, int skip, Document fields){
return new Cursor(_collection.Find(spec, limit, skip, fields));
}
-
- public Document FindAndModify (Document doc, Document spec)
+
+ /// <summary>
+ /// Executes a query and atomically applies a modifier operation to the first document returning the original document
+ /// by default.
+ /// </summary>
+ /// <param name="document">The document.</param>
+ /// <param name="spec"><see cref="Document"/> to find the document.</param>
+ /// <returns>A <see cref="Document"/></returns>
+ public Document FindAndModify (Document document, Document spec)
{
- throw new System.NotImplementedException();
+ return _collection.FindAndModify(document, spec);
}
-
-
- public Document FindAndModify (Document doc, Document spec, Document sort)
+
+ /// <summary>
+ /// Executes a query and atomically applies a modifier operation to the first document returning the original document
+ /// by default.
+ /// </summary>
+ /// <param name="document">The document.</param>
+ /// <param name="spec"><see cref="Document"/> to find the document.</param>
+ /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the</param>
+ /// <returns>A <see cref="Document"/></returns>
+ /// <see cref="IndexOrder"/>
+ public Document FindAndModify (Document document, Document spec, Document sort)
{
- throw new System.NotImplementedException();
+ return _collection.FindAndModify(document, spec, sort);
}
-
-
- public Document FindAndModify (Document doc, Document spec, bool ReturnNew)
+
+ /// <summary>
+ /// Executes a query and atomically applies a modifier operation to the first document returning the original document
+ /// by default.
+ /// </summary>
+ /// <param name="document">The document.</param>
+ /// <param name="spec"><see cref="Document"/> to find the document.</param>
+ /// <param name="returnNew">if set to <c>true</c> [return new].</param>
+ /// <returns>A <see cref="Document"/></returns>
+ public Document FindAndModify (Document document, Document spec, bool returnNew)
{
- throw new System.NotImplementedException();
+ return _collection.FindAndModify(document, spec, returnNew);
}
-
-
- public Document FindAndModify (Document doc, Document spec, Document sort, bool ReturnNew)
+
+ /// <summary>
+ /// Executes a query and atomically applies a modifier operation to the first document returning the original document
+ /// by default.
+ /// </summary>
+ /// <param name="document">The document.</param>
+ /// <param name="spec"><see cref="Document"/> to find the document.</param>
+ /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
+ /// <see cref="IndexOrder"/></param>
+ /// <param name="returnNew">if set to <c>true</c> [return new].</param>
+ /// <returns>A <see cref="Document"/></returns>
+ public Document FindAndModify (Document document, Document spec, Document sort, bool returnNew)
{
- throw new System.NotImplementedException();
+ return _collection.FindAndModify(document, spec, sort, returnNew);
}
/// <summary>
View
148 MongoDBDriver/MongoCollection_1.cs
@@ -3,6 +3,7 @@
using System.IO;
using MongoDB.Driver.Connections;
using MongoDB.Driver.Protocol;
+using MongoDB.Driver.Results;
using MongoDB.Driver.Serialization;
namespace MongoDB.Driver
@@ -149,85 +150,72 @@ public MongoCollection(ISerializationFactory serializationFactory, Connection co
spec = new Document();
return new Cursor<T>(_serializationFactory, _connection, FullName, spec, limit, skip, fields);
}
-
+
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
- /// <param name="doc">
- /// <see cref="Document"/> to use when applying the update.
- /// </param>
- /// <param name="spec">
- /// <see cref="Document"/> to find the document.
- /// </param>
- /// <returns>
- /// A <see cref="Document"/>
- /// </returns>
- public T FindAndModify(object doc, object spec){
- throw new NotImplementedException();
+ /// <param name="document">The document.</param>
+ /// <param name="spec"><see cref="Document"/> to find the document.</param>
+ /// <returns>A <see cref="Document"/></returns>
+ public T FindAndModify(object document, object spec){
+ return FindAndModify(document, spec, false);
}
-
+
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
- /// <param name="doc">
- /// <see cref="Document"/> to use when applying the update.
- /// </param>
- /// <param name="spec">
- /// <see cref="Document"/> to find the document.
- /// </param>
- /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
+ /// <param name="document">The document.</param>
+ /// <param name="spec"><see cref="Document"/> to find the document.</param>
+ /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the</param>
+ /// <returns>A <see cref="Document"/></returns>
/// <see cref="IndexOrder"/>
- /// <returns>
- /// A <see cref="Document"/>
- /// </returns>
- public T FindAndModify(object doc, object spec, object sort){
- throw new NotImplementedException();
+ public T FindAndModify(object document, object spec, object sort){
+ return FindAndModify(document, spec, sort);
}
-
+
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
- /// <param name="doc">
- /// <see cref="Document"/> to use when applying the update.
- /// </param>
- /// <param name="spec">
- /// <see cref="Document"/> to find the document.
- /// </param>
- /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
- /// <see cref="IndexOrder"/>
- /// </param>
- /// <returns>
- /// A <see cref="Document"/>
- /// </returns>
- public T FindAndModify(object doc, object spec, bool ReturnNew){
- throw new NotImplementedException();
+ /// <param name="document">The document.</param>
+ /// <param name="spec"><see cref="Document"/> to find the document.</param>
+ /// <param name="returnNew">if set to <c>true</c> [return new].</param>
+ /// <returns>A <see cref="Document"/></returns>
+ public T FindAndModify(object document, object spec, bool returnNew){
+ return FindAndModify(document, spec, new Document(), returnNew);
}
-
+
/// <summary>
/// Executes a query and atomically applies a modifier operation to the first document returning the original document
/// by default.
/// </summary>
- /// <param name="doc">
- /// <see cref="Document"/> to use when applying the update.
- /// </param>
- /// <param name="spec">
- /// <see cref="Document"/> to find the document.
- /// </param>
- /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
- /// <see cref="IndexOrder"/>
- /// </param>
- /// <param name="ReturnNew">By default the original unmodified document is returned. Pass in true to override this and
- /// get the modified document back.
- /// <returns>
- /// A <see cref="Document"/>
- /// </returns>
- public T FindAndModify(object doc, object spec, object sort, bool ReturnNew){
- throw new NotImplementedException();
+ /// <param name="document">The document.</param>
+ /// <param name="spec"><see cref="Document"/> to find the document.</param>
+ /// <param name="sort"><see cref="Document"/> containing the names of columns to sort on with the values being the
+ /// <see cref="IndexOrder"/></param>
+ /// <param name="returnNew">if set to <c>true</c> [return new].</param>
+ /// <returns>A <see cref="Document"/></returns>
+ public T FindAndModify(object document, object spec, object sort, bool returnNew){
+ try
+ {
+ var response = _database.SendCommand<FindAndModifyResult<T>>(new Document{
+ {"findandmodify", Name},
+ {"query", spec},
+ {"update", EnsureUpdateDocument(document)},
+ {"sort", sort},
+ {"new", returnNew}});
+
+ return response.Value;
+ }
+ catch(MongoCommandException)
+ {
+ // This is when there is no document to operate on
+ return null;
+ }
}
-
+
/// <summary>
/// Entrypoint into executing a map/reduce query against the collection.
/// </summary>
@@ -457,22 +445,7 @@ public void Update(object document, bool safemode)
/// <param name="document">The document.</param>
/// <param name="selector">The selector.</param>
public void UpdateAll(object document, object selector){
- var foundOp = false;
-
- var descriptor = _serializationFactory.GetObjectDescriptor(typeof(T));
-
- foreach (var name in descriptor.GetMongoPropertyNames(document))
- if (name.IndexOf('$') == 0) {
- foundOp = true;
- break;
- }
-
- if (foundOp == false) {
- //wrap document in a $set.
- document = new Document().Add("$set", document);
- }
-
- Update(document, selector, UpdateFlags.MultiUpdate);
+ Update(EnsureUpdateDocument(document), selector, UpdateFlags.MultiUpdate);
}
/// <summary>
@@ -558,5 +531,32 @@ public void Save(object document, bool safemode)
if (ErrorTranslator.IsError(previousError))
throw ErrorTranslator.Translate(previousError);
}
+
+ /// <summary>
+ /// Ensures the update document.
+ /// </summary>
+ /// <param name="document">The document.</param>
+ /// <returns></returns>
+ private object EnsureUpdateDocument(object document)
+ {
+ var foundOp = false;
+
+ var descriptor = _serializationFactory.GetObjectDescriptor(typeof(T));
+
+ foreach(var name in descriptor.GetMongoPropertyNames(document))
+ if(name.IndexOf('$') == 0)
+ {
+ foundOp = true;
+ break;
+ }
+
+ if(foundOp == false)
+ {
+ //wrap document in a $set.
+ return new Document().Add("$set", document);
+ }
+
+ return document;
+ }
}
}
View
9 MongoDBDriver/MongoDB.Driver.csproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -101,7 +101,9 @@
<Compile Include="Bson\BsonWriterSettings.cs" />
<Compile Include="Bson\IBsonObjectBuilder.cs" />
<Compile Include="Bson\IBsonObjectDescriptor.cs" />
+ <Compile Include="IMongoDatabase.cs" />
<Compile Include="Mo.cs" />
+ <Compile Include="Results\FindAndModifyResult.cs" />
<Compile Include="Serialization\Builders\ArrayBuilder.cs" />
<Compile Include="Serialization\Builders\ConcreteClassMapBuilder.cs" />
<Compile Include="Serialization\Builders\DocumentBuilder.cs" />
@@ -121,7 +123,7 @@
<Compile Include="Serialization\IObjectDescriptor.cs" />
<Compile Include="Serialization\SerializationFactory.cs" />
<Compile Include="Exceptions\UnmappedMemberException.cs" />
- <Compile Include="CommandResults\CommandResultBase.cs" />
+ <Compile Include="Results\CommandResultBase.cs" />
<Compile Include="Configuration\CollectionAdapters\ArrayListCollectionAdapter.cs" />
<Compile Include="Configuration\CollectionAdapters\GenericListCollectionAdapter.cs" />
<Compile Include="Configuration\CollectionAdapters\GenericSetCollectionAdapter.cs" />
@@ -175,7 +177,6 @@
<Compile Include="Configuration\Mapping\Model\PersistentMemberMap.cs" />
<Compile Include="Configuration\Mapping\Model\SubClassMap.cs" />
<Compile Include="Connections\RawConnection.cs" />
- <Compile Include="IMongoDatabase.cs" />
<Compile Include="CollectionMetadata.cs" />
<Compile Include="Connections\Connection.cs" />
<Compile Include="Connections\ConnectionFactory.cs" />
@@ -249,8 +250,6 @@
<Compile Include="IMongoCollection_1.cs" />
<Compile Include="Util\ReflectionExtensions.cs" />
<Compile Include="MongoSymbol.cs" />
- <Compile Include="IMongoDatabase.cs" />
- <Compile Include="IMongoDatabase.cs" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
View
3  MongoDBDriver/MongoDatabase.cs
@@ -2,9 +2,8 @@
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
-
-using MongoDB.Driver.CommandResults;
using MongoDB.Driver.Connections;
+using MongoDB.Driver.Results;
using MongoDB.Driver.Serialization;
View
325 MongoDBDriver/MongoSymbol.cs
@@ -1,90 +1,235 @@
-using System;
-
-namespace MongoDB.Driver
-{
-
- /// <summary>
- /// Type to hold an interned string that maps to the bson symbol type.
- /// </summary>
- public struct MongoSymbol : IEquatable<MongoSymbol>, IEquatable<String>, IComparable<MongoSymbol>, IComparable<String>
- {
- public string Value{get; private set;}
-
-
- public MongoSymbol(string val){
- if(string.IsNullOrEmpty(val)) throw new ArgumentNullException("Symbol Value");
- this.Value = String.Intern(val);
-
- }
-
- public override string ToString (){
- return this.Value;
- }
-
- public override bool Equals (object obj){
- return Value.Equals(obj);
- }
-
- public bool Equals (MongoSymbol other){
- return Value.Equals(other.Value);
- }
-
- public bool Equals (string other){
- return Value.Equals(other);
- }
-
- public int CompareTo (MongoSymbol other){
- return Value.CompareTo(other.Value);
- }
-
- public int CompareTo (string other){
- return Value.CompareTo(other);
- }
-
- public static bool operator ==(MongoSymbol a, MongoSymbol b){
- return SymbolEqual(a.Value, b.Value);
- }
-
- public static bool operator ==(MongoSymbol a, string b){
- return SymbolEqual(a.Value, b);
- }
-
- public static bool operator ==(string a, MongoSymbol b){
- return SymbolEqual(a, b.Value);
- }
- public static bool operator !=(MongoSymbol a, MongoSymbol b){
- return !(a == b);
- }
-
- public static bool operator !=(MongoSymbol a, String b){
- return !(a == b);
- }
-
- public static bool operator !=(string a, MongoSymbol b){
- return !(a == b);
- }
-
- public static implicit operator string(MongoSymbol s){
- return s.Value;
- }
-
- public static implicit operator MongoSymbol(string s){
- return new MongoSymbol(s);
- }
-
- private static MongoSymbol _empty;
- public static MongoSymbol Empty{
- get{
- return _empty;
- }
- }
-
- public static bool IsEmpty(MongoSymbol s){
- return s == _empty;
- }
-
- private static bool SymbolEqual(string a, string b){
- return a == b;
- }
- }
-}
+using System;
+
+namespace MongoDB.Driver
+{
+ /// <summary>
+ /// Type to hold an interned string that maps to the bson symbol type.
+ /// </summary>
+ public struct MongoSymbol : IEquatable<MongoSymbol>, IEquatable<String>, IComparable<MongoSymbol>, IComparable<String>
+ {
+ /// <summary>
+ /// Gets or sets the empty.
+ /// </summary>
+ /// <value>The empty.</value>
+ public static MongoSymbol Empty { get; private set; }
+
+ /// <summary>
+ /// Initializes the <see cref="MongoSymbol"/> struct.
+ /// </summary>
+ static MongoSymbol(){
+ Empty = new MongoSymbol();
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="MongoSymbol"/> struct.
+ /// </summary>
+ /// <param name="value">The value.</param>
+ public MongoSymbol(string value)
+ : this(){
+ if(string.IsNullOrEmpty(value))
+ throw new ArgumentNullException("value");
+
+ Value = String.Intern(value);
+ }
+
+ /// <summary>
+ /// Gets or sets the value.
+ /// </summary>
+ /// <value>The value.</value>
+ public string Value { get; private set; }
+
+ /// <summary>
+ /// Compares the current object with another object of the same type.
+ /// </summary>
+ /// <param name="other">An object to compare with this object.</param>
+ /// <returns>
+ /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings:
+ /// Value
+ /// Meaning
+ /// Less than zero
+ /// This object is less than the <paramref name="other"/> parameter.
+ /// Zero
+ /// This object is equal to <paramref name="other"/>.
+ /// Greater than zero
+ /// This object is greater than <paramref name="other"/>.
+ /// </returns>
+ public int CompareTo(MongoSymbol other){
+ return Value.CompareTo(other.Value);
+ }
+
+ /// <summary>
+ /// Compares the current object with another object of the same type.
+ /// </summary>
+ /// <param name="other">An object to compare with this object.</param>
+ /// <returns>
+ /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has the following meanings:
+ /// Value
+ /// Meaning
+ /// Less than zero
+ /// This object is less than the <paramref name="other"/> parameter.
+ /// Zero
+ /// This object is equal to <paramref name="other"/>.
+ /// Greater than zero
+ /// This object is greater than <paramref name="other"/>.
+ /// </returns>
+ public int CompareTo(string other){
+ return Value.CompareTo(other);
+ }
+
+ /// <summary>
+ /// Indicates whether the current object is equal to another object of the same type.
+ /// </summary>
+ /// <param name="other">An object to compare with this object.</param>
+ /// <returns>
+ /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
+ /// </returns>
+ public bool Equals(MongoSymbol other){
+ return Value.Equals(other.Value);
+ }
+
+ /// <summary>
+ /// Indicates whether the current object is equal to another object of the same type.
+ /// </summary>
+ /// <param name="other">An object to compare with this object.</param>
+ /// <returns>
+ /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false.
+ /// </returns>
+ public bool Equals(string other){
+ return Value.Equals(other);
+ }
+
+ /// <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 Value;
+ }
+
+ /// <summary>
+ /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
+ /// </summary>
+ /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
+ /// <returns>
+ /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
+ /// </returns>
+ public override bool Equals(object obj){
+ return Value.Equals(obj);
+ }
+
+ /// <summary>
+ /// Implements the operator ==.
+ /// </summary>
+ /// <param name="a">A.</param>
+ /// <param name="b">The b.</param>
+ /// <returns>The result of the operator.</returns>
+ public static bool operator ==(MongoSymbol a, MongoSymbol b){
+ return SymbolEqual(a.Value, b.Value);
+ }
+
+ /*
+ /// <summary>
+ /// Implements the operator ==.
+ /// </summary>
+ /// <param name="a">A.</param>
+ /// <param name="b">The b.</param>
+ /// <returns>The result of the operator.</returns>
+ public static bool operator ==(MongoSymbol a, string b){
+ return SymbolEqual(a.Value, b);
+ }*/
+
+ /*
+ /// <summary>
+ /// Implements the operator ==.
+ /// </summary>
+ /// <param name="a">A.</param>
+ /// <param name="b">The b.</param>
+ /// <returns>The result of the operator.</returns>
+ public static bool operator ==(string a, MongoSymbol b){
+ return SymbolEqual(a, b.Value);
+ }*/
+
+ /// <summary>
+ /// Implements the operator !=.
+ /// </summary>
+ /// <param name="a">A.</param>
+ /// <param name="b">The b.</param>
+ /// <returns>The result of the operator.</returns>
+ public static bool operator !=(MongoSymbol a, MongoSymbol b){
+ return !(a == b);
+ }
+
+ /*
+ /// <summary>
+ /// Implements the operator !=.
+ /// </summary>
+ /// <param name="a">A.</param>
+ /// <param name="b">The b.</param>
+ /// <returns>The result of the operator.</returns>
+ public static bool operator !=(MongoSymbol a, String b){
+ return !(a == b);
+ }*/
+
+ /*
+ /// <summary>
+ /// Implements the operator !=.
+ /// </summary>
+ /// <param name="a">A.</param>
+ /// <param name="b">The b.</param>
+ /// <returns>The result of the operator.</returns>
+ public static bool operator !=(string a, MongoSymbol b){
+ return !(a == b);
+ }*/
+
+ /// <summary>
+ /// Performs an implicit conversion from <see cref="MongoDB.Driver.MongoSymbol"/> to <see cref="System.String"/>.
+ /// </summary>
+ /// <param name="s">The s.</param>
+ /// <returns>The result of the conversion.</returns>
+ public static implicit operator string(MongoSymbol s){
+ return s.Value;
+ }
+
+ /// <summary>
+ /// Performs an implicit conversion from <see cref="System.String"/> to <see cref="MongoDB.Driver.MongoSymbol"/>.
+ /// </summary>
+ /// <param name="s">The s.</param>
+ /// <returns>The result of the conversion.</returns>
+ public static implicit operator MongoSymbol(string s){
+ return new MongoSymbol(s);
+ }
+
+ /// <summary>
+ /// Determines whether the specified s is empty.
+ /// </summary>
+ /// <param name="s">The s.</param>
+ /// <returns>
+ /// <c>true</c> if the specified s is empty; otherwise, <c>false</c>.
+ /// </returns>
+ public static bool IsEmpty(MongoSymbol s){
+ return s == Empty;
+ }
+
+ /// <summary>
+ /// Symbols the equal.
+ /// </summary>
+ /// <param name="a">A.</param>
+ /// <param name="b">The b.</param>
+ /// <returns></returns>
+ private static bool SymbolEqual(string a, string b){
+ return a == b;
+ }
+
+ /// <summary>
+ /// Returns a hash code for this instance.
+ /// </summary>
+ /// <returns>
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
+ /// </returns>
+ public override int GetHashCode(){
+ return Value.GetHashCode();
+ }
+ }
+}
View
2  ...river/CommandResults/CommandResultBase.cs → MongoDBDriver/Results/CommandResultBase.cs
@@ -1,6 +1,6 @@
using MongoDB.Driver.Attributes;
-namespace MongoDB.Driver.CommandResults
+namespace MongoDB.Driver.Results
{
/// <summary>
///
View
11 MongoDBDriver/Results/FindAndModifyResult.cs
@@ -0,0 +1,11 @@
+namespace MongoDB.Driver.Results
+{
+ internal class FindAndModifyResult<T> : CommandResultBase
+ {
+ /// <summary>
+ /// Gets or sets the value.
+ /// </summary>
+ /// <value>The value.</value>
+ public T Value { get; set; }
+ }
+}
View
2  MongoDBDriver/Serialization/Descriptors/ClassMapPropertyDescriptor.cs
@@ -10,7 +10,7 @@ internal class ClassMapPropertyDescriptor : ClassMapPropertyDescriptorBase
private readonly IDictionary<string, object> _extendedProperties;
/// <summary>
- /// Initializes a new instance of the <see cref="ClassMapDescriptor"/> class.
+ /// Initializes a new instance of the <see cref="ClassMapPropertyDescriptor"/> class.
/// </summary>
/// <param name="classMap">The class map.</param>
/// <param name="instance">The instance.</param>
View
2  MongoDBDriver/Serialization/Descriptors/ClassMapPropertyDescriptorBase.cs
@@ -15,7 +15,7 @@ public abstract class ClassMapPropertyDescriptorBase : IPropertyDescriptor
protected readonly IClassMap ClassMap;
/// <summary>
- /// Initializes a new instance of the <see cref="ClassMapDescriptorBase"/> class.
+ /// Initializes a new instance of the <see cref="ClassMapPropertyDescriptorBase"/> class.
/// </summary>
/// <param name="classMap">The class map.</param>
protected ClassMapPropertyDescriptorBase(IClassMap classMap)
View
2  MongoDBDriver/Serialization/Descriptors/DocumentClassMapPropertyDescriptor.cs
@@ -9,7 +9,7 @@ internal class DocumentClassMapPropertyDescriptor : ClassMapPropertyDescriptorBa
private readonly Document _document;
/// <summary>
- /// Initializes a new instance of the <see cref="DocumentClassMapDescriptor"/> class.
+ /// Initializes a new instance of the <see cref="DocumentClassMapPropertyDescriptor"/> class.
/// </summary>
/// <param name="classMap">The class map.</param>
/// <param name="document">The document.</param>
Please sign in to comment.
Something went wrong with that request. Please try again.