Wednesday, 1 July 2015

Sitecore : Datetime Field with Timezone

Working with Date Time and Timezones is always headache. Recently we faced issue with calendar events generated by our sitecore application in different regions. The start date and end date in generated ICS file was failing to show exact date time specific to end user because of the difference in timezones.

Why that happened?

Curretly there is no mechanism in sitecore to store date and time in different timezones. It simply considers the server timezone - on which the sitecore instance runs - and stores date time accordingly.  So, to make datetime field independent of any specific timezone (more specifically - server timezone) , we needed a custom field that stores UTC (Universal Coordinated Time) , a globally unique datetime, as raw value and presents timezone specific date and time to the content authors.

Note: We can easily do conversion of UTC to any timezone and visa versa, with .NET globalization API


How this prototype works?

Here is how the new field looks to content authors.


This is what sitecore stores in backend.


You can notice the raw value is the UTC equivalent of the IST time content authors can see. And this is the secret of this field :)

You might be wondering from where the the timezone India Standard Time is coming??
 -  In our application, we have separated all settings from actual content items, and those settings are globally applicable to entire site (something like AppSettings in .net application)

-  So here the timezone IST is coming from site level settings, which looks like this



-  Based on above selection, only the display date and time will change, but the raw value will remain same.

Friday, 19 June 2015

Transfer Sitecore User Accounts with Passwords from One Instance to Another

Sometimes you need to transfer sitecore users from one instance to another instance having different databases.

For this, you can serialize your users from source instance and then deserialize them on destination instance.

Steps to perform this task

1.  Serialize Users on Source Instance :
 To serialize users, open Content Editor - Security - User Manager





Thursday, 7 May 2015

MongoDB M101N Final Exam Question 10

Question 10:

We perform the following query on the enron dataset:

var exp = db.messages.explain('executionStats')

exp.find( { 'headers.Date' : { '$gt' : new Date(2001,3,1) } }, { 'headers.From' : 1, '_id' : 0 } ).sort( { 'headers.From' : 1 } )


and get the following explain output.  

MongoDB M101N Final Exam Question 9

Question 9:

Imagine an electronic medical record database designed to hold the medical records of every individual in the United States. Because each person has more than 16MB of medical history and records, it's not feasible to have a single document for every patient. Instead, there is a patient collection that contains basic information on each person and maps the person to a patient_id, and a record collection that contains one document for each test or procedure. One patient may have dozens or even hundreds of documents in the record collection.
We need to decide on a shard key to shard the record collection. What's the best shard key for the record collection, provided that we are willing to run inefficient scatter-gather operations to do infrequent research and run studies on various diseases and cohorts? That is, think mostly about the operational aspects of such a system. And by operational, we mean, think about what the most common operations that this systems needs to perform day in and day out.

MongoDB M101N Final Exam Question 8

Question 8:

Supposed we executed the following C# code. How many animals will be inserted into the "animals" collection?

using MongoDB.Bson;
using MongoDB.Driver;
using System.Threading.Tasks;

namespace M101DotNet
{
    class InsertTest
    {
        static void Main(string[] args)
        {
            MainAsync(args).GetAwaiter().GetResult();
        }

        static async Task MainAsync(string[] args)
        {
            var client = new MongoClient();
            var db = client.GetDatabase("test");

            var animals = db.GetCollection<BsonDocument>("animals");

            var animal = new BsonDocument
                            {
                            {"animal", "monkey"}
                            };

            await animals.InsertOneAsync(animal);
            animal.Remove("animal");
            animal.Add("animal", "cat");
            animal["_id"] = ObjectId.GenerateNewId();
            await animals.InsertOneAsync(animal);
            animal.Remove("animal");
            animal.Add("animal", "lion");
            animal["_id"] = ObjectId.GenerateNewId();
            await animals.InsertOneAsync(animal);
        }
    }
}

MongoDB M101N Final Exam Question 7

Question 7:

You have been tasked to cleanup a photo-sharing database. The database consists of two collections, albums, and images. Every image is supposed to be in an album, but there are orphan images that appear in no album. Here are some example documents (not from the collections you will be downloading). 

> db.albums.findOne()
{
    "_id" : 67
    "images" : [
        4745,
        7651,
        15247,
        17517,
        17853,
        20529,
        22640,
        27299,
        27997,
        32930,
        35591,
        48969,
        52901,
        57320,
        96342,
        99705
    ]
}

> db.images.findOne()
{ "_id" : 99705, "height" : 480, "width" : 640, "tags" : [ "dogs", "kittens", "work" ] }


Wednesday, 6 May 2015

MongoDB M101N Final Exam Question 6

Question 6:

Suppose you have a collection of students of the following form:
{
 "_id" : ObjectId("50c598f582094fb5f92efb96"),
 "first_name" : "John",
 "last_name" : "Doe",
 "date_of_admission" : ISODate("2010-02-21T05:00:00Z"),
 "residence_hall" : "Fairweather",
 "has_car" : true,
 "student_id" : "2348023902",
 "current_classes" : [
  "His343",
  "Math234",
  "Phy123",
  "Art232"
 ]
}

Now suppose that basic inserts into the collection, which only include the last name, first name and student_id, are too slow (we can't do enough of them per second from our program). What could potentially improve the speed of inserts. Check all that apply.