Updating nested arrays in mongodb

Here’s the big question, do you need to leverage Mongo’s “addToSet” and “push” operations? If you really plan to modify just individual items in the array, then you should probably build these arrays as objects. Here’s how I would structure this: { id: 1, items: { “2” : { “blocks” : { “3” : { … Read more

Convert HttpPostedFileBase to byte[]

As Darin says, you can read from the input stream – but I’d avoid relying on all the data being available in a single go. If you’re using .NET 4 this is simple: MemoryStream target = new MemoryStream(); model.File.InputStream.CopyTo(target); byte[] data = target.ToArray(); It’s easy enough to write the equivalent of CopyTo in .NET 3.5 … Read more

Swift JSONDecode decoding arrays fails if single element decoding fails

One option is to use a wrapper type that attempts to decode a given value; storing nil if unsuccessful: struct FailableDecodable<Base : Decodable> : Decodable { let base: Base? init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() self.base = try? container.decode(Base.self) } } We can then decode an array of these, with your … Read more

Swift 3.0: compiler error when calling global func min(T,T) in Array or Dictionary extension

I see no reason why the compiler shouldn’t be able to resolve this function call, therefore I would consider it a bug (it has already been filed – see SR-2450). It seems to occur whenever attempting to call a top-level function with the same name, but unambiguously different signature to a method or property that’s … Read more

Get-ChildItem.Length is Wrong

PetSerAl, as many times before, has provided the crucial pointer in a terse comment on the question (and he’s also assisted in refining this answer): $pathChildren = @(Get-ChildItem -Path $strPath) The use of @(…), the array subexpression operator, ensures that whatever the enclosed command outputs is treated as an array, even if only 1 object … Read more

Accessing a JSON object in Bash – associative array / list / another model

If you want key and value, and based on How do i convert a json object to key=value format in JQ, you can do: $ jq -r “to_entries|map(\”\(.key)=\(.value|tostring)\”)|.[]” file SALUTATION=Hello world SOMETHING=bla bla bla Mr. Freeman In a more general way, you can store the values into an array myarray[key] = value like this, just … Read more