Permalink
Browse files

C# driver 1.8

  • Loading branch information...
1 parent 4a17858 commit f80a96ba4c55d797371015514b45c2c534207b29 @nightroman committed Mar 20, 2013
View
@@ -1,7 +1,7 @@
@{
Author = 'Roman Kuzmin'
- ModuleVersion = '3.0.1'
+ ModuleVersion = '3.0.2'
CompanyName = 'https://github.com/nightroman/Mdbc'
Description = 'Mdbc module - MongoDB Cmdlets for PowerShell'
Copyright = '(C) 2011-2013 Roman Kuzmin. All rights reserved.'
@@ -485,7 +485,10 @@ Renames the field with name 'old_field_name' to 'new_field_name'. Does not
expand arrays to find a match for 'old_field_name'.
'@
Set = '{ $set : { field : value } }', @'
-Sets field to value. All data types are supported.
+Sets a field value. All data types are supported.
+'@
+ SetOnInsert = '{ $setOnInsert : { field : value } }', @'
+Sets a field value during upsert only when insert is performed. All data types are supported.
'@
Unset = '{ $unset : { field : 1} }', @'
Deletes a given field.
@@ -506,6 +509,7 @@ Deletes a given field.
PushAll = '$pushAll argument, a collection of values, each value is pushed.'
Rename = '$rename argument, the new field name.'
Set = '$set argument. All standard types are supported.'
+ SetOnInsert = '$setOnInsert argument. All standard types are supported.'
Unset = 'Tells to remove the field.'
}
inputs = @()
View
@@ -1,6 +1,12 @@
Mdbc Release Notes
==================
+## v3.0.2
+
+C# driver 1.8
+
+`New-MdbcData` - new parameter `SetOnInsert`.
+
## v3.0.1
C# driver 1.7.1
View
@@ -37,9 +37,9 @@ static class Actor
switch (value.BsonType)
{
case BsonType.Array: return new Collection((BsonArray)value); // wrapper
- case BsonType.Binary: return value.RawValue ?? value; // byte[] or Guid else self
- case BsonType.Boolean: return value.RawValue;
- case BsonType.DateTime: return ((BsonDateTime)value).Value;
+ case BsonType.Binary: return BsonTypeMapper.MapToDotNetValue(value) ?? value; // byte[] or Guid else self
+ case BsonType.Boolean: return BsonTypeMapper.MapToDotNetValue(value);
+ case BsonType.DateTime: return ((BsonDateTime)value).ToUniversalTime();
case BsonType.Document: return new Dictionary((BsonDocument)value); // wrapper
case BsonType.Double: return ((BsonDouble)value).Value;
case BsonType.Int32: return ((BsonInt32)value).Value;
@@ -271,7 +271,7 @@ public static IMongoUpdate ObjectToUpdate(object value)
var enumerable = LanguagePrimitives.GetEnumerable(value);
if (enumerable != null)
- return Update.Combine(enumerable.Cast<object>().Select(Actor.ObjectToUpdate).Cast<UpdateBuilder>());
+ return Update.Combine(enumerable.Cast<object>().Select(Actor.ObjectToUpdate));
throw new PSInvalidCastException("Invalid update type. Valid types: update, dictionary.");
}
View
@@ -4,7 +4,7 @@
using System;
[assembly: AssemblyProduct("Mdbc")]
-[assembly: AssemblyVersion("3.0.1")]
+[assembly: AssemblyVersion("3.0.2")]
[assembly: AssemblyTitle("Mdbc module - MongoDB Cmdlets for PowerShell")]
[assembly: AssemblyCompany("https://github.com/nightroman/Mdbc")]
[assembly: AssemblyCopyright("Copyright (c) 2011-2013 Roman Kuzmin")]
@@ -34,7 +34,7 @@ void WriteDocument(BsonDocument document)
if (Id != null)
document["_id"] = BsonValue.Create(Id.BaseObject);
else if (NewId)
- document["_id"] = BsonObjectId.GenerateNewId();
+ document["_id"] = new BsonObjectId(ObjectId.GenerateNewId());
WriteObject(new Dictionary(document));
}
@@ -35,6 +35,7 @@ public sealed class NewUpdateCommand : PSCmdlet
const string NPushAll = "PushAll";
const string NRename = "Rename";
const string NSet = "Set";
+ const string NSetOnInsert = "SetOnInsert";
const string NUnset = "Unset";
const string ExpectedInteger = "Invalid value type. Expected types: int, long.";
const string ExpectedNumber = "Invalid value type. Expected types: int, long, double.";
@@ -67,6 +68,9 @@ public sealed class NewUpdateCommand : PSCmdlet
[Parameter(Position = 1, Mandatory = true, ParameterSetName = NSet)]
[AllowNull]
public PSObject Set { get; set; }
+ [Parameter(Position = 1, Mandatory = true, ParameterSetName = NSetOnInsert)]
+ [AllowNull]
+ public PSObject SetOnInsert { get; set; }
[Parameter(Position = 1, Mandatory = true, ParameterSetName = NUnset)]
public SwitchParameter Unset { get; set; }
UpdateBuilder BuildBand()
@@ -166,6 +170,10 @@ protected sealed override void BeginProcessing()
WriteObject(Update.Set(Name, Actor.ToBsonValue(Set)));
return;
+ case NSetOnInsert:
+ WriteObject(Update.SetOnInsert(Name, Actor.ToBsonValue(SetOnInsert)));
+ return;
+
case NUnset:
WriteObject(Update.Unset(Name));
return;
@@ -16,7 +16,6 @@
using System;
using System.Collections;
-using System.Collections.Generic;
using System.Management.Automation;
using MongoDB.Bson;
using MongoDB.Bson.IO;
@@ -51,7 +50,7 @@ static IList ReadArray(BsonReader bsonReader)
switch (bsonReader.GetCurrentBsonType())
{
case BsonType.Array: return ReadArray(bsonReader); // replacement
- case BsonType.Binary: var binary = BsonBinaryData.ReadFrom(bsonReader); return binary.RawValue ?? binary; // byte[] or Guid else self
+ case BsonType.Binary: var binary = BsonSerializer.Deserialize<BsonValue>(bsonReader); return BsonTypeMapper.MapToDotNetValue(binary) ?? binary; // byte[] or Guid else self
case BsonType.Boolean: return bsonReader.ReadBoolean();
case BsonType.DateTime: return BsonUtils.ToDateTimeFromMillisecondsSinceEpoch(bsonReader.ReadDateTime());
case BsonType.Document: return ReadCustomObject(bsonReader); // replacement
@@ -60,7 +59,7 @@ static IList ReadArray(BsonReader bsonReader)
case BsonType.Int64: return bsonReader.ReadInt64();
case BsonType.Null: bsonReader.ReadNull(); return null;
case BsonType.String: return bsonReader.ReadString();
- default: return BsonValue.ReadFrom(bsonReader);
+ default: return BsonSerializer.Deserialize<BsonValue>(bsonReader);
}
}
static PSObject ReadCustomObject(BsonReader bsonReader)
@@ -30,5 +30,5 @@ catch {
$message = "$_"
}
if ($message -ne @'
-Command 'create' failed: collection already exists (response: { "errmsg" : "collection already exists", "ok" : 0.0 })
-'@) {throw}
+Command 'create' failed: collection already exists (response: { "ok" : 0.0, "errmsg" : "collection already exists" })
+'@) {throw $message}
@@ -7,11 +7,11 @@ Connect-Mdbc . test test -NewCollection
# NB: `function` looks optional and `this` is all we need
$map = <#js#>@'
-//function() {
+function() {
for (var key in this) {
emit(key, {count : 1})
}
-//}
+}
'@
# NB: http://stackoverflow.com/a/65028/323582

0 comments on commit f80a96b

Please sign in to comment.